Skip to content

Commit

Permalink
Merge pull request #54 from ansari-project/fix-build
Browse files Browse the repository at this point in the history
Fix continuous testing.
  • Loading branch information
waleedkadous authored Oct 19, 2024
2 parents fba0a22 + f38f13c commit cc24e3a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 20 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ share/
pyvenv.cfg
example_projects/
abandoned/
build/
data/
datasources/
etc/
Expand Down
31 changes: 14 additions & 17 deletions agents/ansari.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,13 @@ def replace_message_history(self, message_history ):

@observe(capture_input = False,capture_output = False)
def process_message_history(self):
langfuse_context.update_current_trace(
user_id = self.message_logger.user_id,
session_id = str(self.message_logger.thread_id),
tags = ['debug', 'replace_message_history'],
input = self.message_history
)
if self.message_logger is not None:
langfuse_context.update_current_trace(
user_id = self.message_logger.user_id,
session_id = str(self.message_logger.thread_id),
tags = ['debug', 'replace_message_history'],
input = self.message_history
)
# Keep processing the user input until we get something from the assistant
self.start_time = datetime.now()
count = 0
Expand Down Expand Up @@ -121,11 +122,6 @@ def process_message_history(self):

@observe(as_type="generator")
def process_one_round(self, use_function=True):
langfuse_context.update_current_trace(
user_id = self.message_logger.user_id,
session_id = str(self.message_logger.thread_id),
tags = ['debug', 'replace_message_history']
)
response = None
failures = 0
while not response:
Expand All @@ -136,6 +132,7 @@ def process_one_round(self, use_function=True):
model=self.model,
messages=self.message_history,
stream=True,
stream_options = {"include_usage": True},
functions=self.functions,
timeout=30.0,
temperature=0.0,
Expand All @@ -148,6 +145,7 @@ def process_one_round(self, use_function=True):
model=self.model,
messages=self.message_history,
stream=True,
stream_options = {"include_usage": True},
functions=self.functions,
timeout=30.0,
temperature=0.0,
Expand All @@ -160,6 +158,7 @@ def process_one_round(self, use_function=True):
model=self.model,
messages=self.message_history,
stream=True,
stream_options = {"include_usage": True},
timeout=30.0,
temperature=0.0,
response_format={"type": "json_object"},
Expand All @@ -171,6 +170,7 @@ def process_one_round(self, use_function=True):
model=self.model,
messages=self.message_history,
stream=True,
stream_options = {"include_usage": True},
timeout=30.0,
temperature=0.0,
metadata={"generation-name": "ansari"},
Expand All @@ -193,7 +193,9 @@ def process_one_round(self, use_function=True):
function_arguments = ""
response_mode = "" # words or fn
for tok in response:
logger.debug(f"Tok is {tok}")
if len(tok.choices) == 0: # in case usage is defind.q
logging.warning(f"Token has no choices: {tok}")
langfuse_context.update_current_observation(usage = tok.usage)
delta = tok.choices[0].delta
if not response_mode:
# This code should only trigger the first
Expand Down Expand Up @@ -250,11 +252,6 @@ def process_one_round(self, use_function=True):

@observe()
def process_fn_call(self, orig_question, function_name, function_arguments):
langfuse_context.update_current_trace(
user_id = self.message_logger.user_id,
session_id = str(self.message_logger.thread_id),
tags = ['debug', 'replace_message_history']
)
if function_name in self.tools.keys():
args = json.loads(function_arguments)
query = args["query"]
Expand Down
6 changes: 3 additions & 3 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ class Settings(BaseSettings):
VECTARA_CORPUS_ID: str
DISCORD_TOKEN: Optional[SecretStr] = Field(default=None)
SENDGRID_API_KEY: Optional[SecretStr] = Field(default=None)
LANGFUSE_SECRET_KEY: SecretStr = Field(default=None)
LANGFUSE_PUBLIC_KEY: SecretStr = Field(default=None)
LANGFUSE_HOST: str = Field(default=None)
LANGFUSE_SECRET_KEY: Optional[SecretStr] = Field(default=None)
LANGFUSE_PUBLIC_KEY: Optional[SecretStr] = Field(default=None)
LANGFUSE_HOST: Optional[str] = Field(default=None)

template_dir: DirectoryPath = Field(default="resources/templates")
diskcache_dir: str = Field(default="diskcache_dir")
Expand Down

0 comments on commit cc24e3a

Please sign in to comment.