Skip to content

Commit

Permalink
Try/catch in chatters
Browse files Browse the repository at this point in the history
  • Loading branch information
jrrobison1 committed Apr 4, 2024
1 parent 7a3852c commit 0461c4f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
21 changes: 12 additions & 9 deletions llm_writer_workshop/chatter/mistral_chatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,18 @@ def __init__(
temperature=DEFAULT_TEMPERATURE,
name
):
self.mistral_api_key = os.environ.get("MISTRAL_API_KEY")
self.model = model
self.max_output_tokens = max_output_tokens
self.temperature = temperature
self.name = name
self.message_history = []
self.client = MistralClient(api_key=self.mistral_api_key)
self.initial_prompt = ChatMessage(role="system", content=system_prompt)
self.message_history.append(self.initial_prompt)
try:
self.mistral_api_key = os.environ.get("MISTRAL_API_KEY")
self.model = model
self.max_output_tokens = max_output_tokens
self.temperature = temperature
self.name = name
self.message_history = []
self.client = MistralClient(api_key=self.mistral_api_key)
self.initial_prompt = ChatMessage(role="system", content=system_prompt)
self.message_history.append(self.initial_prompt)
except Exception as e:
print(e)

def chat(self, message):
if message != "":
Expand Down
19 changes: 11 additions & 8 deletions llm_writer_workshop/chatter/openai_chatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@ def __init__(
name,
max_output_tokens=DEFAULT_SYSTEM_PROMPT
):
self.model = model
self.max_output_tokens = max_output_tokens
self.name = name
self.initial_prompt = {"role": "system", "content": system_prompt}
self.message_history = []
self.message_history.append(self.initial_prompt)
self.openai_api_key = os.environ.get("OPENAI_API_KEY")
self.open_ai_client = OpenAI(api_key=self.openai_api_key)
try:
self.model = model
self.max_output_tokens = max_output_tokens
self.name = name
self.initial_prompt = {"role": "system", "content": system_prompt}
self.message_history = []
self.message_history.append(self.initial_prompt)
self.openai_api_key = os.environ.get("OPENAI_API_KEY")
self.open_ai_client = OpenAI(api_key=self.openai_api_key)
except Exception as e:
print(e)

def chat(self, message):
user_message = {}
Expand Down

0 comments on commit 0461c4f

Please sign in to comment.