Merge pull request #5 from BerriAI/add-replicate

Update main.py
This commit is contained in:
Ishaan Jaff 2023-07-27 20:45:49 -07:00 committed by GitHub
commit 2463dc234b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -34,6 +34,32 @@ def completion(model, messages, azure=False):
engine=model,
messages = messages
)
elif "replicate" in model:
prompt = " ".join([message["content"] for message in messages])
output = replicate.run(
model,
input={
"prompt": prompt,
})
print(f"output: {output}")
response = ""
for item in output:
print(f"item: {item}")
response += item
new_response = {
"choices": [
{
"finish_reason": "stop",
"index": 0,
"message": {
"content": response,
"role": "assistant"
}
}
]
}
print(f"new response: {new_response}")
response = new_response
elif model in cohere_models:
cohere_key = os.environ.get("COHERE_API_KEY")
co = cohere.Client(cohere_key)