This repository was archived by the owner on Jul 31, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclient.py
More file actions
59 lines (46 loc) · 1.9 KB
/
client.py
File metadata and controls
59 lines (46 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import os
from dotenv import load_dotenv
from cellium.client import CelliumClient
load_dotenv()
def get_agent() -> CelliumClient:
"""
Instantiates the CelliumClient and sets its API key and model based on the values in the .env file.
If the .env file does not specify an API key or model, the client falls back to using the default values.
Returns:
AgentArtificial: The instantiated client.
"""
client = CelliumClient()
# The client checks your .env file for which API key and model to use
# Default is CelliumClient with a fall back of OpenAI.
client.api_key = client.choose_api_key()
# Use the choose method to auto select.
client.model = str(object=os.getenv(key="AGENTARTIFICIAL_MODEL"))
# Or you can load them normally
client.url = str(object=os.getenv(key="AGENTARTIFICIAL_URL"))
# now the client works the same as openai's client.
return client
if __name__ == "__main__":
get_agent()
def example():
"""
Calls the get_agent function to instantiate an CelliumClient.
Creates a chat completion using the instantiated agent client.
The completion is based on a set of messages and returns the content of the first choice from the completion response.
"""
client: CelliumClient = get_agent()
# Creating a chat completion is the same as openai
response = client.chat.completions.create(
model=client.model,
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Who won the world series in 2020?"},
{
"role": "assistant",
"content": "The Los Angeles Dodgers won the World Series in 2020.",
},
{"role": "user", "content": "Where was it played?"},
],
)
return response["data"]["choices"][0]["message"]["content"]
if __name__ == "__main__":
get_agent()