Skip to content

Commit

Permalink
WIP. Working
Browse files Browse the repository at this point in the history
  • Loading branch information
HowieG committed May 10, 2024
1 parent 155ba66 commit a800383
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
20 changes: 13 additions & 7 deletions agentops/llm_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def handle_stream_chunk(chunk):
if isinstance(chunk, StreamedChatResponse_StreamStart):
self.llm_event.returns = chunk
self.llm_event.agent_id = check_call_stack_for_agent_id()
self.llm_event.model = kwargs.get("model", "command")
self.llm_event.model = kwargs.get("model", "command-r-plus")
self.llm_event.prompt = kwargs["message"]
self.llm_event.completion = ""
return
Expand Down Expand Up @@ -297,18 +297,24 @@ def generator():
yield chunk
return generator()

# TODO: we should record if they pass a chat.connectors, because it means they intended to call a tool
# Not enough to record StreamedChatResponse_ToolCallsGeneration because the tool may have not gotten called

try:
self.llm_event.returns = response.dict()
self.llm_event.agent_id = check_call_stack_for_agent_id()
self.llm_event.prompt = []
for message in response.chat_history:
# TODO: bug where message repeats
self.llm_event.prompt.append({"role": "assistant", "content": kwargs["message"]})
self.llm_event.prompt.append({"role": "assistant", "content": kwargs["message"]})
if response.chat_history:
for i in range(len(response.chat_history) - 1):
message = response.chat_history[i]
self.llm_event.prompt.append({"role": message.role, "content": message.message})

last_message = response.chat_history[-1]
self.llm_event.completion = {
"role": response.chat_history[-1].role, "content": response.chat_history[-1].message}
self.llm_event.prompt_tokens = response.meta.tokens.input_tokens
self.llm_event.completion = {"role": "assistant", "content": response.text}
self.llm_event.completion_tokens = response.meta.tokens.output_tokens
self.llm_event.model = kwargs["model"]
self.llm_event.model = kwargs.get("model", "command-r-plus")

self.client.record(self.llm_event)
except Exception as e:
Expand Down
7 changes: 4 additions & 3 deletions tests/test_cohere.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@

chat = co.chat(
chat_history=[
{"role": "USER", "message": "Who discovered gravity?"},
{
"role": "CHATBOT",
"content": "test"
}
"message": "The man who is widely credited with discovering gravity is Sir Isaac Newton",
},
],
message="hello world!",
message="What year was he born?",
model="command"
)

Expand Down

0 comments on commit a800383

Please sign in to comment.