Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fs 80/use https for webagent search #21

Merged
merged 15 commits into from
Nov 22, 2024

Conversation

gaganahluwalia
Copy link
Collaborator

Description

This change is to make sure we are only using 'https' websites for our web search and scraping.
Also made a small change the way Web Search was being used after the usual LLM based on the LLM's answer.

Changelog

  • Mainly the Web_Agent.py and Web_utils.py

@@ -1,73 +1,75 @@
import logging
from unittest.mock import Mock, patch
# import logging
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If these tests aren't needed any more then they should be deleted and not just commented out.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests deleted

2. **Validity Check**: The LLM checks if its generated answer is complete and correct. This could be based on factual accuracy, coverage of the query, or relevance to the user's question.
3. **Validation Reason**: The LLM explains why the answer is valid or invalid.
2. **Search More**: If a more general web search using a web search engine is required then indicate that, it should set this field to true.
4. **Validation Reason**: The LLM explains why the answer is valid or invalid.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this now be named something like "search more reason" and should the text be changed to address the changes on line 28

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed it to search_more_reason

2. **Validity Check**: The LLM checks if its generated answer is complete and correct. This could be based on factual accuracy, coverage of the query, or relevance to the user's question.
3. **Validation Reason**: The LLM explains why the answer is valid or invalid.
2. **Search More**: If a more general web search using a web search engine is required then indicate that, it should set this field to true.
4. **Validation Reason**: The LLM explains why the answer is valid or invalid.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why has this point changed to 4. ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to 3

try:
for url in search(search_query, num_results=num_results):
urls.append(url)
https_urls = [str(url) for url in search(search_query, num_results=num_results) if str(url).startswith("https")]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to test this by mocking out search library?

### **Explanation:**

1. **Answer**: The LLM generates an answer based on the user’s question and the provided content.
2. **Validity Check**: The LLM checks if its generated answer is complete and correct. This could be based on factual accuracy, coverage of the query, or relevance to the user's question.
3. **Validation Reason**: The LLM explains why the answer is valid or invalid.
2. **Search More**: If a more general web search using a web search engine is required then indicate that, it should set this field to true.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be renamed "should perform web search"?

Am I correct in understanding that when we trigger a web_general_search from the WebAgent we're getting to this prompt first and attempting to answer the question using the underlying models training data, and if it doesn't have info we then perform a web search?

@@ -9,23 +9,24 @@ User's question is:
Once you generate an answer:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this file (and all references) be renamed to "answer-user-question"

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Sorry to add some housekeeping!)

valid_answer = json.loads(answer_result["response"]).get("is_valid", "")
if valid_answer:
search_more = json.loads(answer_result["response"]).get("search_more", "")
if not search_more:
Copy link
Collaborator

@IMladjenovic IMladjenovic Nov 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a bit of extra safety, can we also update perform_scrape method in this class to verify that the urls it has been given are https? This method would be a good one to add tests for as well

@@ -81,3 +82,35 @@ async def test_web_general_search_core_invalid_summary(
}
assert json.loads(result) == expected_response

@pytest.mark.asyncio
@patch("src.utils.web_utils.search")
async def test_https_urls(mock_search):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


assert result["value"] == "Y", (
# Allow `expected_response` to be a list of possible valid responses
possible_responses = [resp.strip() for resp in expected_response.split(",")]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's good that this now support multiple possible answers.
I guess the implication of splitting on , and then doing a contains check for each substring though is that the resulting check is less strict. E.g. for a question like
Check the database and tell me the fund with the lowest Governance ESG score with an expected response of
Dynamics Industries, Silvermans Global ETF, WhiteRocks ETF, which has a score of 60.

This would pass for any answer that contains one of those fund names or which contains which has a score of 60.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mic-smith - I get your point, so what do you suggest we should do?

Copy link
Collaborator

@mic-smith mic-smith Nov 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we could repeat the whole string in each option e.g. Dynamics Industries which has a score of 60, Silvermans Global ETF which has a score of 60, WhiteRocks ETF which has a score of 60 maybe with a different separator than , so it's more obvious? Though not sure how well that would work with the case we need to use an LLM because the response isn't a substring.

We're also commenting out these datasource based tests in #23 . So, I wonder if it's worth pulling these test changes into in a separate branch so it doesn't block this PR and then addressing once we have the new flow to upload data and a different data set available?

@@ -38,8 +38,8 @@ async def web_general_search_core(search_query, llm, model) -> str:
}
return json.dumps(response, indent=4)
logger.info(f'Answer found successfully {answer_result}')
valid_answer = json.loads(answer_result["response"]).get("is_valid", "")
if valid_answer:
perform_web_search = json.loads(answer_result["response"]).get("perform_web_search", "")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be should_perform_web_search too I think

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

variable name not changed

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@evpearce - Done..

@gaganahluwalia gaganahluwalia merged commit c9566e0 into main Nov 22, 2024
4 checks passed
@gaganahluwalia gaganahluwalia deleted the FS-80/Use-HTTPS-For-Webagent-Search branch November 22, 2024 09:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants