Skip to content

Commit

Permalink
fix alllama usage (remove usage tracking)
Browse files Browse the repository at this point in the history
  • Loading branch information
ericcccsliu committed Apr 26, 2024
1 parent 9ebcc77 commit 5d3fe04
Showing 1 changed file with 0 additions and 14 deletions.
14 changes: 0 additions & 14 deletions api/utils/llm_providers/alllama.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
# api/utils/llm_providers/alllama.py

import tiktoken
from openai import AsyncOpenAI
from starlette.config import Config

from api.utils.conversation_utils import update_user_usage

config = Config(".env")
client = AsyncOpenAI(
base_url=config("ALLLAMA_API_BASE_URL"), api_key=config("ALLLAMA_API_KEY")
Expand All @@ -17,10 +13,6 @@ async def alllama_generate_response(conversation):
for message in conversation.messages
]

# Count the input tokens
encoding = tiktoken.encoding_for_model(conversation.model.name)
input_tokens = sum(len(encoding.encode(message["content"])) for message in messages)

stream = await client.chat.completions.create(
max_tokens=1500,
model=conversation.model.name,
Expand All @@ -29,16 +21,10 @@ async def alllama_generate_response(conversation):
)

collected_chunks = []
output_tokens = 0
async for chunk in stream:
content = chunk.choices[0].delta.content
if content is None:
content = ""
collected_chunks.append(content)
output_tokens += len(encoding.encode(content))
yield content

# Update the user's usage
await update_user_usage(
conversation.user_email, conversation.model.name, input_tokens, output_tokens
)

0 comments on commit 5d3fe04

Please sign in to comment.