| import os |
| import cohere.core |
| import instructor |
| import cohere |
| import instructor |
|
|
|
|
| from pydantic import BaseModel, Field |
|
|
| from typing import List, Dict |
| from pydantic import BaseModel |
|
|
|
|
| class Scene(BaseModel): |
| narration: str |
| image_prompts: List[str] |
|
|
|
|
| class VideoOutput(BaseModel): |
| scenes: List[Scene] |
|
|
|
|
| |
| client = instructor.from_cohere( |
| cohere.Client( |
| os.environ.get( |
| "COHERE_API", |
| ) |
| ), |
| |
| model="command-r-plus", |
| ) |
|
|
|
|
| |
| |
|
|
|
|
| def chatbot(prompt: str, model: str = "command-r-plus"): |
|
|
| response: VideoOutput = client.chat.completions.create( |
| model=model, |
| |
| response_model=VideoOutput, |
| messages=[ |
| { |
| "role": "user", |
| "content": prompt, |
| }, |
| ], |
| ) |
| return response.dict() |
|
|
|
|
| |
|
|