| from openai import OpenAI
|
| class LlaMa3:
|
| def __init__(self) -> None:
|
| self.client = OpenAI(
|
| base_url="https://integrate.api.nvidia.com/v1",
|
| api_key="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"
|
| )
|
| self.name = "Llama3"
|
|
|
|
|
| self.initial_prompt = """
|
| Hello! I can assist you in making a decision. What decision would you like to make today?
|
| Please describe the decision and provide any relevant details to help me understand.
|
| """
|
|
|
| def chat(self, messages):
|
|
|
| if len(messages) == 0:
|
| messages.append({"role": "system", "content": self.initial_prompt})
|
|
|
|
|
| completion = self.client.chat.completions.create(
|
| model="nvidia/llama-3.1-nemotron-70b-instruct",
|
| messages=messages,
|
| temperature=0.5,
|
| top_p=1,
|
| max_tokens=1024,
|
| stream=True
|
| )
|
|
|
| response = ""
|
| for chunk in completion:
|
| if chunk.choices[0].delta.content is not None:
|
| response += chunk.choices[0].delta.content
|
|
|
| return response
|
|
|