Skip to content

Commit

Permalink
Merge pull request #110 from valory-xyz/feat/prediction-tool
Browse files Browse the repository at this point in the history
Feat/prediction tool
  • Loading branch information
0xArdi authored Sep 12, 2023
2 parents be7410c + 1b2be0b commit 03378e2
Show file tree
Hide file tree
Showing 3 changed files with 360 additions and 20 deletions.
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,9 @@ fix-abci-app-specs:
echo "Successfully validated abcis!"

protolint_install:
GO111MODULE=on GOPATH=~/go go get -u -v github.com/yoheimuta/protolint/cmd/[email protected]
mkdir protolint_install
cd protolint_install && \
wget https://github.com/yoheimuta/protolint/releases/download/v0.27.0/protolint_0.27.0_Linux_x86_64.tar.gz && \
tar -xvf protolint_0.27.0_Linux_x86_64.tar.gz && \
sudo mv protolint /usr/local/bin/protolint
sudo rm -rf protolint_install
23 changes: 4 additions & 19 deletions tools/prediction_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import json
from concurrent.futures import Future, ThreadPoolExecutor
from typing import Any, Dict, Generator, List, Optional, Tuple
from dataclasses import dataclass

import openai
import requests
Expand Down Expand Up @@ -112,10 +111,6 @@
* Output only the JSON object. Do not include any other contents in your response.
"""

@dataclass
class SMERolePrompt:
sme: str
sme_introduction: str

def search_google(query: str, api_key: str, engine: str, num: int = 3) -> List[str]:
service = build("customsearch", "v1", developerKey=api_key)
Expand Down Expand Up @@ -238,9 +233,6 @@ def run(**kwargs) -> Tuple[str, Optional[Dict[str, Any]]]:
"""Run the task"""
tool = kwargs["tool"]
prompt = kwargs["prompt"]
# this is optional
if kwargs.get("sme_role_system_prompt"):
sme_role_system_prompt: SMERolePrompt = SMERolePrompt(**kwargs["sme_role_system_prompt"])
max_tokens = kwargs.get("max_tokens", DEFAULT_OPENAI_SETTINGS["max_tokens"])
temperature = kwargs.get("temperature", DEFAULT_OPENAI_SETTINGS["temperature"])

Expand All @@ -267,17 +259,10 @@ def run(**kwargs) -> Tuple[str, Optional[Dict[str, Any]]]:
moderation_result = openai.Moderation.create(prediction_prompt)
if moderation_result["results"][0]["flagged"]:
return "Moderation flagged the prompt as in violation of terms.", None
if sme_role_system_prompt:
print(f"You are using SME: {sme_role_system_prompt.sme}")
messages = [
{"role": "system", "content": sme_role_system_prompt.sme_introduction},
{"role": "user", "content": prediction_prompt},
]
else:
messages = [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": prediction_prompt},
]
messages = [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": prediction_prompt},
]
response = openai.ChatCompletion.create(
model=engine,
messages=messages,
Expand Down
Loading

0 comments on commit 03378e2

Please sign in to comment.