-
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.
Merge pull request #181 from zeus-fyi/mb-python
Mb python
- Loading branch information
Showing
28 changed files
with
1,067 additions
and
0 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
Empty file.
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,30 @@ | ||
import json | ||
|
||
import requests | ||
|
||
from examples.mockingbird.python.api_setup import api_v1_path, get_headers | ||
|
||
|
||
def create_agg_task(task): | ||
url = api_v1_path + "/tasks/ai" | ||
headers = get_headers() | ||
response = requests.post(url, json=task, headers=headers) | ||
# Check the response status | ||
if response.status_code == 200: | ||
print("Task created successfully!") | ||
else: | ||
print(response.json()) | ||
print("Failed to create task. Status Code:", response.status_code) | ||
|
||
|
||
if __name__ == '__main__': | ||
with open('templates/aggregation.json', 'r') as file: | ||
payload = json.load(file) | ||
|
||
payload['taskName'] = 'demo-agg-task' | ||
payload['taskGroup'] = 'demo' | ||
payload['model'] = 'gpt-3.5-turbo-0125' | ||
payload['prompt'] = ('how do you think AI will respond to being offered a' | ||
' decision tree with cost assigned options and a budget?') | ||
|
||
create_agg_task(payload) |
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,46 @@ | ||
import json # Import the json module | ||
|
||
import requests | ||
|
||
from examples.mockingbird.python.api_setup import get_headers, api_v1_path | ||
|
||
|
||
def get_task(tid): | ||
url = api_v1_path + "/task/ai/" + tid | ||
headers = get_headers() | ||
response = requests.get(url, headers=headers) | ||
|
||
if response.status_code == 200: | ||
task_data = response.json() | ||
pretty_task_data = json.dumps(task_data, indent=4) | ||
with open('task-' + tid + '.json', 'w') as json_file: | ||
json.dump(task_data, json_file, indent=4) | ||
print(pretty_task_data) | ||
else: | ||
print("Failed to fetch task data. Status Code:", response.status_code) | ||
|
||
|
||
def create_analysis_task(task): | ||
url = api_v1_path + "/tasks/ai" | ||
print(url) | ||
headers = get_headers() | ||
response = requests.post(url, json=task, headers=headers) | ||
# Check the response status | ||
if response.status_code == 200: | ||
print("Task created successfully!") | ||
else: | ||
print(response.json()) | ||
print("Failed to create task. Status Code:", response.status_code) | ||
|
||
|
||
if __name__ == '__main__': | ||
with open('templates/analysis.json', 'r') as file: | ||
payload = json.load(file) | ||
|
||
payload['taskName'] = 'demo-analysis-task' | ||
payload['taskGroup'] = 'demo' | ||
payload['model'] = 'gpt-3.5-turbo-0125' | ||
payload['prompt'] = ('how do you think AI will respond to being offered a' | ||
' decision tree with cost assigned options and a budget?') | ||
print(payload) | ||
create_analysis_task(payload) |
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 @@ | ||
import yaml | ||
|
||
config_file_path = '../../../test/configs/config.yaml' | ||
with open(config_file_path, 'r') as file: | ||
config = yaml.safe_load(file) | ||
|
||
bearer_token = config.get('BEARER', '') | ||
headers = { | ||
'Authorization': f'Bearer {bearer_token}' | ||
} | ||
|
||
api_v1_path = "https://api.zeus.fyi/v1" | ||
|
||
|
||
# api_v1_path = "http://localhost:9001/v1" | ||
|
||
|
||
def get_headers(): | ||
# Read the config file and extract the BEARER token | ||
with open(config_file_path, 'r') as fl: | ||
cfg = yaml.safe_load(fl) | ||
|
||
bt = cfg.get('BEARER', '') | ||
|
||
# Create and return the headers dictionary with the Authorization field | ||
hdrs = { | ||
'Authorization': f'Bearer {bt}' | ||
} | ||
return hdrs |
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,62 @@ | ||
import json # Import the json module | ||
|
||
import requests | ||
|
||
from examples.mockingbird.python.api_setup import get_headers, api_v1_path | ||
from examples.mockingbird.python.triggers import trigger_function_template | ||
|
||
|
||
def get_evals(): | ||
url = api_v1_path + "/evals/ai" | ||
headers = get_headers() | ||
response = requests.get(url, headers=headers) | ||
if response.status_code == 200: | ||
data = response.json() | ||
pretty_data = json.dumps(data, indent=4) | ||
print(pretty_data) | ||
else: | ||
print("Status Code:", response.status_code) | ||
|
||
|
||
def create_or_update_eval(eval_fn): | ||
url = api_v1_path + "/evals/ai" | ||
headers = get_headers() | ||
response = requests.post(url, json=eval_fn, headers=headers) | ||
if response.status_code == 200: | ||
data = response.json() | ||
pretty_data = json.dumps(data, indent=4) | ||
print(pretty_data) | ||
else: | ||
print("Status Code:", response.status_code) | ||
|
||
|
||
if __name__ == '__main__': | ||
with open('templates/eval_fn.json', 'r') as file: | ||
eval_fn_pl = json.load(file) | ||
|
||
# for updating an existing eval function use id | ||
# eval_fn_str_id = '1709068762300906000' | ||
# eval_fn_pl['evalStrID'] = eval_fn_str_id | ||
|
||
eval_fn_pl['evalName'] = 'demo-eval-fn' | ||
eval_fn_pl['evalGroup'] = 'demo' | ||
eval_fn_pl['evalFormat'] = 'json' | ||
eval_fn_pl['evalModel'] = 'gpt-4-0125-preview' | ||
|
||
# Add schema | ||
with open('google_search_regex/schema.json', 'r') as file: | ||
efn_schema = json.load(file) | ||
|
||
efn_schema['schemaStrID'] = '1708624962876732000' | ||
efn_schema['fields'][0]['fieldStrID'] = '1708580020120821000' | ||
eval_fn_pl['schemas'] = [efn_schema] | ||
|
||
# Add trigger | ||
trigger_str_id = '1708624962876732000' | ||
trigger_function_template['triggerStrID'] = trigger_str_id | ||
eval_fn_pl['triggerFunctions'] = [trigger_function_template] | ||
|
||
pretty_task_data = json.dumps(eval_fn_pl, indent=4) | ||
print(pretty_task_data) | ||
|
||
create_or_update_eval(eval_fn_pl) |
16 changes: 16 additions & 0 deletions
16
examples/mockingbird/python/google_search_regex/agg_task.json
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,16 @@ | ||
[ | ||
{ | ||
"taskStrID": "0", | ||
"taskID": 0, | ||
"maxTokensPerTask": 0, | ||
"taskType": "aggregation", | ||
"taskName": "biz-lead-google-search-summary", | ||
"taskGroup": "google-search", | ||
"tokenOverflowStrategy": "deduce", | ||
"model": "gpt-4-0125-preview", | ||
"temperature": 1, | ||
"marginBuffer": 0.5, | ||
"prompt": "Can you summarize the relevant person and/or associated business from the search results? It should use the most relevant search result that matches best and ignore others to prevent mixing multiple profiles. I want to know what this person does and what kind of role they perform, and summarize any other details that you can find and you should add more weight to LinkedIn information, you should strive for accuracy over greater inclusion.", | ||
"responseFormat": "text" | ||
} | ||
] |
89 changes: 89 additions & 0 deletions
89
examples/mockingbird/python/google_search_regex/analysis_task.json
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,89 @@ | ||
[ | ||
{ | ||
"taskStrID": "0", | ||
"taskID": 0, | ||
"maxTokensPerTask": 0, | ||
"taskType": "analysis", | ||
"taskName": "zeusfyi-verbatim", | ||
"taskGroup": "default", | ||
"tokenOverflowStrategy": "deduce", | ||
"model": "gpt-4-0125-preview", | ||
"temperature": 1, | ||
"marginBuffer": 0.5, | ||
"prompt": "Name, company", | ||
"schemas": [ | ||
{ | ||
"schemaID": 0, | ||
"schemaStrID": "0", | ||
"schemaName": "google-search-query-params", | ||
"schemaGroup": "google-search", | ||
"schemaDescription": "Gets query value string for google api call", | ||
"isObjArray": false, | ||
"fields": [ | ||
{ | ||
"fieldID": 0, | ||
"fieldStrID": "0", | ||
"fieldName": "q", | ||
"fieldDescription": "this will be a google search query string to look up more information about the request shown.\n\nexample: prompt: \"business: openai, person: brockman\", response: \"what does brockman do at openai\"\n\nyou should not add ? in your response", | ||
"dataType": "string" | ||
} | ||
] | ||
} | ||
], | ||
"schemasMap": { | ||
"0": { | ||
"schemaID": 0, | ||
"schemaStrID": "0", | ||
"schemaName": "google-search-query-params", | ||
"schemaGroup": "google-search", | ||
"schemaDescription": "Gets query value string for google api call", | ||
"isObjArray": false, | ||
"fields": [ | ||
{ | ||
"fieldID": 0, | ||
"fieldStrID": "", | ||
"fieldName": "q", | ||
"fieldDescription": "this will be a google search query string to look up more information about the request shown.\n\nexample: prompt: \"business: openai, person: brockman\", response: \"what does brockman do at openai\"\n\nyou should not add ? in your response", | ||
"dataType": "string" | ||
} | ||
] | ||
} | ||
}, | ||
"responseFormat": "json", | ||
"evalFns": [ | ||
{ | ||
"evalID": 0, | ||
"evalName": "google-seach-query-param", | ||
"evalType": "model", | ||
"evalGroupName": "google-search", | ||
"evalModel": "gpt-4-0125-preview", | ||
"evalFormat": "json", | ||
"schemas": [ | ||
{ | ||
"schemaID": 0, | ||
"schemaName": "google-search-query-params", | ||
"schemaGroup": "google-search", | ||
"schemaDescription": "Gets query value string for google api call", | ||
"isObjArray": false, | ||
"fields": [ | ||
{ | ||
"fieldID": 0, | ||
"fieldName": "q", | ||
"fieldDescription": "this will be a google search query string to look up more information about the request shown.\n\nexample: prompt: \"business: openai, person: brockman\", response: \"what does brockman do at openai\"\n\nyou should not add ? in your response", | ||
"dataType": "string", | ||
"evalMetrics": [ | ||
{ | ||
"evalMetricID": 0, | ||
"evalOperator": "length-less-than", | ||
"evalState": "filter", | ||
"evalExpectedResultState": "pass" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] |
61 changes: 61 additions & 0 deletions
61
examples/mockingbird/python/google_search_regex/eval_fn.json
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,61 @@ | ||
{ | ||
"evalStrID": "0", | ||
"evalID": 0, | ||
"evalName": "google-seach-query-param", | ||
"evalType": "model", | ||
"evalGroupName": "google-search", | ||
"evalModel": "gpt-4-0125-preview", | ||
"evalFormat": "json", | ||
"triggerFunctions": [ | ||
{ | ||
"triggerStrID": "0", | ||
"triggerID": 0, | ||
"triggerName": "google-qp-search-regex", | ||
"triggerGroup": "google-search", | ||
"triggerAction": "api-retrieval", | ||
"evalTriggerActions": [ | ||
{ | ||
"evalID": 0, | ||
"evalStrID": "0", | ||
"triggerID": 0, | ||
"triggerStrID": "0", | ||
"evalTriggerState": "filter", | ||
"evalResultsTriggerOn": "all-pass" | ||
} | ||
] | ||
} | ||
], | ||
"schemas": [ | ||
{ | ||
"schemaID": 0, | ||
"schemaStrID": "0", | ||
"schemaName": "google-search-query-params", | ||
"schemaGroup": "google-search", | ||
"schemaDescription": "Gets query value string for google api call", | ||
"isObjArray": false, | ||
"fields": [ | ||
{ | ||
"fieldID": 0, | ||
"fieldStrID": "0", | ||
"fieldName": "q", | ||
"fieldDescription": "this will be a google search query string to look up more information about the request shown.\n\nexample: prompt: \"business: openai, person: brockman\", response: \"what does brockman do at openai\"\n\nyou should not add ? in your response", | ||
"dataType": "string", | ||
"evalMetrics": [ | ||
{ | ||
"evalMetricID": 0, | ||
"evalOperator": "length-less-than", | ||
"evalState": "filter", | ||
"evalExpectedResultState": "pass", | ||
"evalMetricComparisonValues": { | ||
"evalComparisonBoolean": false, | ||
"evalComparisonNumber": 0, | ||
"evalComparisonString": "100", | ||
"evalComparisonInteger": 0 | ||
} | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} |
Oops, something went wrong.