-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #277 from Eyobyb/feature/number-verification
number validation
- Loading branch information
Showing
17 changed files
with
372 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,17 @@ | ||
from abc import ABC, abstractmethod | ||
from typing import Tuple | ||
|
||
|
||
class BaseOutputParser(ABC): | ||
@abstractmethod | ||
def parse_output(self, text: str) -> str: | ||
pass | ||
|
||
|
||
class BaseOutputProcessor(ABC): | ||
@abstractmethod | ||
def process_output(self, text: str) -> Tuple[bool, str]: | ||
pass | ||
|
||
def __call__(self, text: str) -> Tuple[bool, str]: | ||
return self.process_output(text) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from typing import Tuple | ||
|
||
from sherpa_ai.memory import Belief | ||
from sherpa_ai.output_parsers.base import BaseOutputProcessor | ||
from sherpa_ai.output_parsers.validation_result import ValidationResult | ||
from sherpa_ai.utils import check_if_number_exist | ||
|
||
|
||
class NumberValidation(BaseOutputProcessor): | ||
def __init__( | ||
self, | ||
source: str, | ||
): | ||
self.source = source | ||
|
||
def process_output(self, text: str) -> ValidationResult: | ||
check_validation = check_if_number_exist(text, self.source) | ||
if check_validation["number_exists"]: | ||
return ValidationResult( | ||
is_valid=True, | ||
result=text, | ||
feedback="", | ||
) | ||
else: | ||
return ValidationResult( | ||
is_valid=False, | ||
result=text, | ||
feedback=check_validation["messages"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from pydantic import BaseModel | ||
|
||
|
||
class ValidationResult(BaseModel): | ||
is_valid: bool | ||
result: str | ||
feedback: str = "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
src/tests/data/test_number_citation_validator_test_number_citation_succeeds_in_qa_0.jsonl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{"input": [{"text": "You are a **question answering assistant** who solves user questions and offers a detailed solution.\\n\\nGiven your specialized expertise, historical context, and your mission to facilitate Machine-Learning-based solutions, determine which action and its corresponding arguments would be the most scientifically sound and efficient approach to achieve the described task.\\n\\n**Task Description**: What is the annual salary for an entry level software engineer in Canada?\\n\\n**Possible Actions**:\\n{\\n \"name\": \"Google Search\",\\n \"args\": {\\n \"query\": \"string\"\\n }\\n}\\n\\n**Task Context**:\\nWhat is the annual salary for an entry level software engineer in Canada?\\n\\n\\n**History of Previous Actions**:\\n\\n\\nYou should only respond in JSON format as described below without any extra text.\\nResponse Format:\\n{\\n \"command\": {\\n \"name\": \"tool/command name you choose\",\\n \"args\": {\\n \"arg name\": \"value\"\\n }\\n }\\n}\\nEnsure the response can be parsed by Python json.loads\\n\\nIf you believe the task is complete and no further actions are necessary, respond with \"Finished\".\\n\\nFollow the described fromat strictly.\\n\\n", "agent": "human"}], "output": "{\\n \"command\": {\\n \"name\": \"Google Search\",\\n \"args\": {\\n \"query\": \"annual salary for entry level software engineer in Canada\"\\n }\\n }\\n}", "llm_name": "gpt-3.5-turbo"} | ||
{"input": [{"text": "You are a **question answering assistant** who solves user questions and offers a detailed solution.\\n\\nYour name is QA Agent.\\n\\nContext: What is the annual salary for an entry level software engineer in Canada?\\n\\n\\nAction - Result History:\\nGoogle Search{'query': 'annual salary for entry level software engineer in Canada'}\\nA software engineer is a person who applies the engineering design process to design, develop, test, maintain, and evaluate computer software.\\n The term programmer is sometimes used as a synonym, but may emphasize software implementation over design and can also lack connotations of engineering education or skills.\\n the average annual in Canada is around $9000 to $1,000,170,000 CAD for software engineers\\n\\nGiven the context and the action-result history, please complete the task mentioned. Include any links you used from the context and history in the result.\\nTask: What is the annual salary for an entry level software engineer in Canada?\\nResult:\\n", "agent": "human"}], "output": "The annual salary for an entry-level software engineer in Canada can vary depending on factors such as location, company size, and industry. However, according to the information provided in the action-result history, the average annual salary for software engineers in Canada is around $9,000 to $1,000,170,000 CAD.\\n\\nPlease note that the salary range mentioned in the history seems to be quite broad and may not accurately represent the typical salary for an entry-level software engineer. It is recommended to conduct further research or refer to reliable sources such as job search websites, salary surveys, or industry reports to get a more precise and up-to-date understanding of the salary range for entry-level software engineers in Canada.\\n\\nSources:\\n- [Payscale - Software Engineer Salary in Canada](https://www.payscale.com/research/CA/Job=Software_Engineer/Salary)\\n- [Glassdoor - Software Engineer Salaries in Canada](https://www.glassdoor.ca/Salaries/canada-software-engineer-salary-SRCH_IL.0,6_IN3_KO7,24.htm)", "llm_name": "gpt-3.5-turbo"} | ||
{"input": [{"text": "You are a **question answering assistant** who solves user questions and offers a detailed solution.\\n\\nYour name is QA Agent.\\n\\nContext: What is the annual salary for an entry level software engineer in Canada?\\n\\n\\nAction - Result History:\\nA software engineer is a person who applies the engineering design process to design, develop, test, maintain, and evaluate computer software.\\n The term programmer is sometimes used as a synonym, but may emphasize software implementation over design and can also lack connotations of engineering education or skills.\\n the average annual in Canada is around $9000 to $1,000,170,000 CAD for software engineers\\nGoogle Search{'query': 'annual salary for entry level software engineer in Canada'}Don't use the numbers 3, 06, 724, to answer the question instead stick to the numbers mentioned in the context.\\n\\nGiven the context and the action-result history, please complete the task mentioned. Include any links you used from the context and history in the result.\\nTask: What is the annual salary for an entry level software engineer in Canada?\\nResult:\\n", "agent": "human"}], "output": "The annual salary for an entry level software engineer in Canada is around $90,000 to $100,000 CAD. This information is based on the context provided and the average salary range mentioned. Please note that actual salaries may vary depending on factors such as location, company, and individual qualifications.\\n\\nSources:\\n- Context: No specific source mentioned\\n- Action-Result History: No specific source mentioned", "llm_name": "gpt-3.5-turbo"} | ||
{"input": [{"text": "You are a **question answering assistant** who solves user questions and offers a detailed solution.\\n\\nYour name is QA Agent.\\n\\nContext: What is the annual salary for an entry level software engineer in Canada?\\n\\n\\nAction - Result History:\\nA software engineer is a person who applies the engineering design process to design, develop, test, maintain, and evaluate computer software.\\n The term programmer is sometimes used as a synonym, but may emphasize software implementation over design and can also lack connotations of engineering education or skills.\\n the average annual in Canada is around $9000 to $1,000,170,000 CAD for software engineers\\nGoogle Search{'query': 'annual salary for entry level software engineer in Canada'}Don't use the numbers 3, 06, 724, to answer the question instead stick to the numbers mentioned in the context.\\nDon't use the numbers 100000, 90000, to answer the question instead stick to the numbers mentioned in the context.\\n\\nGiven the context and the action-result history, please complete the task mentioned. Include any links you used from the context and history in the result.\\nTask: What is the annual salary for an entry level software engineer in Canada?\\nResult:\\n", "agent": "human"}], "output": "The annual salary for an entry level software engineer in Canada can vary depending on factors such as location, company size, and industry. However, based on the information provided in the context, the average annual salary for software engineers in Canada is around $9,000 to $1,000,170,000 CAD. It is important to note that these numbers are approximate and may not reflect the exact salary range for entry level positions.\\n\\nPlease keep in mind that the numbers mentioned in the context are quite broad and cover a wide range of salaries. It is recommended to research specific companies and industries to get a more accurate understanding of the salary range for entry level software engineers in Canada.\\n\\nSources:\\n- No specific sources were mentioned in the context or action-result history.", "llm_name": "gpt-3.5-turbo"} |
Oops, something went wrong.