Skip to content

Commit

Permalink
refactor: use OpenAIResponseParser() for all models
Browse files Browse the repository at this point in the history
  • Loading branch information
anyin233 committed Nov 23, 2024
1 parent cb1ac22 commit 924b2f6
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions nerif/utils/token_counter.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,19 @@ def set_parser(self, parser: ResponseParserBase):
self.response_parser = parser

def set_parser_based_on_model(self, model_name: str):
if model_name.startswith("ollama"):
self.set_parser(OllamaResponseParser())
else:
self.set_parser(OpenAIResponseParser())
"""
Sets the response parser based on the provided model name.
Currently, since Ollama's requests are proxied through LiteLLM which formats responses
in OpenAI compatible format, we use OpenAIResponseParser for all responses.
Args:
model_name (str): Name of the model to set parser for
Returns:
None
"""
self.set_parser(OpenAIResponseParser())

def count_from_response(self, response):
"""
Expand Down

0 comments on commit 924b2f6

Please sign in to comment.