Skip to content

Commit

Permalink
fix: misc issues with prediction tool
Browse files Browse the repository at this point in the history
  • Loading branch information
0xArdi committed Oct 19, 2023
1 parent 8ef8e64 commit 3ad71bf
Showing 1 changed file with 6 additions and 30 deletions.
36 changes: 6 additions & 30 deletions tools/optimization_by_prompting.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ def create_new_instructions(llm, instructions, score):
return evaluations


def prompt_engineer(init_instructions, instructions_format, iterations=3, model_name="gpt-3.5-turbo"):
def prompt_engineer(openai_api_key, init_instructions, instructions_format, iterations=3, model_name="gpt-3.5-turbo"):

llm = OpenAI(model_name=model_name)
llm = OpenAI(model_name=model_name, openai_api_key=openai_api_key)
score_template = {"template": init_instructions, "score": 0.0}

df = pd.read_csv(StringIO(EXAMPLES), sep=";")
Expand Down Expand Up @@ -334,35 +334,26 @@ def run(**kwargs) -> Tuple[str, Optional[Dict[str, Any]]]:
"""Run the task"""
tool = kwargs["tool"]
prompt = kwargs["prompt"]
improve_instructions = kwargs["improve_instructions"]
max_tokens = kwargs.get("max_tokens", DEFAULT_OPENAI_SETTINGS["max_tokens"])
temperature = kwargs.get("temperature", DEFAULT_OPENAI_SETTINGS["temperature"])

openai.api_key = kwargs["api_keys"]["openai"]
openai_key = kwargs["api_keys"]["openai"]
openai.api_key = openai_key
if tool not in ALLOWED_TOOLS:
raise ValueError(f"Tool {tool} is not supported.")

engine = TOOL_TO_ENGINE[tool]
additional_information = (
fetch_additional_information(
additional_information = fetch_additional_information(
prompt=prompt,
engine=engine,
temperature=temperature,
max_tokens=max_tokens,
google_api_key=kwargs["api_keys"]["google_api_key"],
google_engine=kwargs["api_keys"]["google_engine_id"],
)
if tool == "prediction-online-sme"
else ""
)

instructions = (
prompt_engineer(PREDICTION_PROMPT_INSTRUCTIONS, PREDICTION_PROMPT_FORMAT)
if improve_instructions
else PREDICTION_PROMPT_INSTRUCTIONS
)
instructions = prompt_engineer(openai_key, PREDICTION_PROMPT_INSTRUCTIONS, PREDICTION_PROMPT_FORMAT)
instructions += PREDICTION_PROMPT_FORMAT

prediction_prompt = instructions.format(
user_prompt=prompt, additional_information=additional_information
)
Expand All @@ -386,18 +377,3 @@ def run(**kwargs) -> Tuple[str, Optional[Dict[str, Any]]]:
stop=None,
)
return response.choices[0].message.content, None


if __name__ == "__main__":
os.environ['OPENAI_API_KEY'] = "your_openai_api_key"
api_keys = {"openai": "your_openai_api_key"}

func_args = {
"api_keys": api_keys,
"tool": "deepmind-optimization",
"prompt": "Will AI take over the world in the next year?",
"improve_instructions": True,
}

response = run(**func_args)
print(response)

0 comments on commit 3ad71bf

Please sign in to comment.