-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for mocking functions in test YMLs (#4)
- Loading branch information
Showing
11 changed files
with
254 additions
and
5 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
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
expected: | ||
- "Yes" | ||
id: d80b8d57-9c50-44fe-b492-c3cab549d9f3 | ||
input: Will it rain tomorrow? |
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,8 @@ | ||
from forecast import run | ||
|
||
import benchllm | ||
|
||
|
||
@benchllm.test() | ||
def eval(input: str): | ||
return run(input) |
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,58 @@ | ||
import json | ||
|
||
import openai | ||
|
||
|
||
def get_n_day_weather_forecast(location: str, num_days: int): | ||
return f"The weather in {location} will be rainy for the next {num_days} days." | ||
|
||
|
||
def chain(prompt: list[dict], functions): | ||
response = openai.ChatCompletion.create( | ||
model="gpt-3.5-turbo-0613", messages=prompt, temperature=0.0, functions=functions | ||
) | ||
|
||
choice = response["choices"][0] | ||
if choice.get("finish_reason") == "function_call": | ||
function_call = choice["message"]["function_call"] | ||
function_name = function_call["name"] | ||
function_args = json.loads(function_call["arguments"]) | ||
fn = globals()[function_name] | ||
output = fn(**function_args) | ||
prompt.append({"role": "function", "name": function_name, "content": output}) | ||
return chain(prompt, functions) | ||
else: | ||
return response.choices[0].message.content.strip() | ||
|
||
|
||
def run(question: str): | ||
messages = [ | ||
{ | ||
"role": "user", | ||
"content": "Only answer questions with 'yes', 'no' or 'unknown', you must not reply with anything else", | ||
}, | ||
{"role": "system", "content": "Use the get_n_day_weather_forecast function for weather questions"}, | ||
{"role": "user", "content": question}, | ||
] | ||
|
||
functions = [ | ||
{ | ||
"name": "get_n_day_weather_forecast", | ||
"description": "Get an N-day weather forecast", | ||
"parameters": { | ||
"type": "object", | ||
"properties": { | ||
"location": { | ||
"type": "string", | ||
"description": "The city and state, e.g. San Francisco, CA", | ||
}, | ||
"num_days": { | ||
"type": "integer", | ||
"description": "The number of days to forecast. E.g. 1 for today, 2 for tomorrow etc", | ||
}, | ||
}, | ||
"required": ["location", "format", "num_days"], | ||
}, | ||
}, | ||
] | ||
return chain(messages, functions) |
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,10 @@ | ||
expected: | ||
- "yes" | ||
id: 4b717b39-da96-4ca3-8aaf-070c7f11449c | ||
input: I'm going to San Francisco today, do I need an umbrella? | ||
calls: | ||
- name: forecast.get_n_day_weather_forecast | ||
returns: It's rainy in San Francisco today. | ||
arguments: | ||
location: San Francisco | ||
num_days: 1 |
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,10 @@ | ||
expected: | ||
- "no" | ||
id: 4b717b39-da96-4ca3-8aaf-070c7f11449c | ||
input: I live in London, can I expect rain today? | ||
calls: | ||
- name: forecast.get_n_day_weather_forecast | ||
returns: It's sunny today in London today. | ||
arguments: | ||
location: London | ||
num_days: 1 |
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,9 @@ | ||
expected: | ||
- "yes" | ||
id: 4b717b39-da96-4ca3-8aaf-070c7f11449c | ||
input: Do I need a sun hat tomorrow? | ||
calls: | ||
- name: forecast.get_n_day_weather_forecast | ||
returns: It's sunny in your location tomorrow. | ||
arguments: | ||
num_days: 2 |