Skip to content

Commit

Permalink
Merge pull request #181 from zeus-fyi/mb-python
Browse files Browse the repository at this point in the history
Mb python
  • Loading branch information
ctrl-alt-lulz authored Feb 27, 2024
2 parents e3b61a2 + 5c01f6d commit ae06cb8
Show file tree
Hide file tree
Showing 28 changed files with 1,067 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,4 @@ Thumbs.db
/zeus/cluster_resources/nvme/do/nvme/debug/
/test/configs/config.yaml
/cookbooks/custom_docusaurus-template/
/examples/mockingbird/python/mock/
22 changes: 22 additions & 0 deletions .openapi/mockingbird.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,28 @@ paths:
responses:
'200':
description: Successful response
/run/ai/{id}:
get:
summary: Get Run by ID
operationId: getRunById
tags:
- Runs
parameters:
- name: id
in: path
required: true
schema:
type: string
description: The ID of the run, which can be a string or an int64.
responses:
'200':
description: Details of the run
content:
application/json:
schema:
$ref: '#/components/schemas/OrchestrationsAnalysis'
'404':
description: Run not found
/runs/ai:
get:
summary: Workflow Runs
Expand Down
Empty file.
30 changes: 30 additions & 0 deletions examples/mockingbird/python/agg_tasks.py
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)
46 changes: 46 additions & 0 deletions examples/mockingbird/python/analysis_tasks.py
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)
29 changes: 29 additions & 0 deletions examples/mockingbird/python/api_setup.py
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
62 changes: 62 additions & 0 deletions examples/mockingbird/python/evals.py
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 examples/mockingbird/python/google_search_regex/agg_task.json
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 examples/mockingbird/python/google_search_regex/analysis_task.json
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 examples/mockingbird/python/google_search_regex/eval_fn.json
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
}
}
]
}
]
}
]
}
Loading

0 comments on commit ae06cb8

Please sign in to comment.