cohere is added but not intergrated, this commit is because it was imported
Browse files- App/Generate/utils/Cohere.py +48 -0
App/Generate/utils/Cohere.py
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import cohere.core
|
3 |
+
import instructor
|
4 |
+
import cohere
|
5 |
+
import instructor
|
6 |
+
|
7 |
+
|
8 |
+
from pydantic import BaseModel, Field
|
9 |
+
|
10 |
+
from typing import List, Dict
|
11 |
+
from pydantic import BaseModel
|
12 |
+
|
13 |
+
|
14 |
+
class Scene(BaseModel):
|
15 |
+
narration: str
|
16 |
+
image_prompts: List[str]
|
17 |
+
|
18 |
+
|
19 |
+
class VideoOutput(BaseModel):
|
20 |
+
scenes: List[Scene]
|
21 |
+
|
22 |
+
|
23 |
+
# Patching the Cohere client with the instructor for enhanced capabilities
|
24 |
+
client = instructor.from_cohere(
|
25 |
+
cohere.Client(os.environ.get("COHERE_API", "RANDOM_STRING")),
|
26 |
+
max_tokens=5000,
|
27 |
+
model="command-r-plus",
|
28 |
+
)
|
29 |
+
|
30 |
+
|
31 |
+
# Now, we can use the response_model parameter using only a base model
|
32 |
+
# rather than having to use the OpenAISchema class
|
33 |
+
|
34 |
+
|
35 |
+
def chatbot(prompt: str, model: str = "command-r-plus"):
|
36 |
+
|
37 |
+
response: VideoOutput = client.chat.completions.create(
|
38 |
+
model=model,
|
39 |
+
max_tokens=5000,
|
40 |
+
response_model=VideoOutput,
|
41 |
+
messages=[
|
42 |
+
{
|
43 |
+
"role": "user",
|
44 |
+
"content": prompt,
|
45 |
+
},
|
46 |
+
],
|
47 |
+
)
|
48 |
+
return response.dict()
|