Skip to content
This repository has been archived by the owner on Jan 5, 2025. It is now read-only.

Commit

Permalink
Merge pull request #193 from openchatai/feat/slack
Browse files Browse the repository at this point in the history
adding prompts to customise behaviour of application
  • Loading branch information
codebanesr authored Oct 27, 2023
2 parents a9fc758 + 789bba6 commit 89653d2
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion llm-server/integrations/custom_prompts/slack.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
flow_generation_prompts = ""

api_generation_prompt = ""
api_generation_prompt = "Use encoded value for channel"
13 changes: 11 additions & 2 deletions llm-server/routes/workflow/extractors/extract_body.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from typing import Any, Optional
from routes.workflow.extractors.extract_json import extract_json_payload
from custom_types.t_json import JsonData
import importlib
import logging

openai_api_key = os.getenv("OPENAI_API_KEY")
Expand All @@ -16,7 +17,7 @@ def gen_body_from_schema(
body_schema: str,
text: str,
prev_api_response: str,
example: str,
app: Optional[str],
current_state: Optional[str],
) -> Any:
chat = ChatOpenAI(
Expand All @@ -25,6 +26,11 @@ def gen_body_from_schema(
temperature=0,
)

if app:
module_name = f"integrations.custom_prompts.{app}"
module = importlib.import_module(module_name)
api_generation_prompt = getattr(module, "api_generation_prompt")

messages = [
SystemMessage(
content="You are an intelligent machine learning model that can produce REST API's body in json format"
Expand All @@ -37,10 +43,13 @@ def gen_body_from_schema(
HumanMessage(content="prev api responses: {}".format(prev_api_response)),
HumanMessage(content="current_state: {}".format(current_state)),
HumanMessage(
content="Given the provided information, generate the appropriate minified JSON payload to use as body for the API request. Avoid using fields that are not required, and user input doesnot require it."
content="Given the provided information, generate the appropriate minified JSON payload to use as body for the API request. If a user doesn't provide a required parameter, use sensible defaults for required params, and leave optional params"
),
]

if api_generation_prompt is not None:
messages.append(HumanMessage(content="{}".format(api_generation_prompt)))

result = chat(messages)

logging.info("[OpenCopilot] LLM Body Response: {}".format(result.content))
Expand Down
5 changes: 3 additions & 2 deletions llm-server/routes/workflow/generate_openapi_payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def generate_openapi_payload(
text: str,
_operation_id: str,
prev_api_response: str,
app: Optional[str],
current_state: Optional[str],
) -> ApiInfo:
(
Expand Down Expand Up @@ -119,12 +120,12 @@ def generate_openapi_payload(
)

if api_info.body_schema:
example = gen_ex_from_schema(api_info.body_schema)
# example = gen_ex_from_schema(api_info.body_schema)
api_info.body_schema = gen_body_from_schema(
json.dumps(api_info.body_schema, separators=(",", ":")),
text,
prev_api_response,
example,
app,
current_state,
)

Expand Down
7 changes: 6 additions & 1 deletion llm-server/routes/workflow/utils/run_openapi_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ def run_openapi_operations(
# refresh state after every api call, we can look into optimizing this later as well
operation_id = step.get("open_api_operation_id")
api_payload = generate_openapi_payload(
swagger_json, text, operation_id, prev_api_response, current_state
swagger_json,
text,
operation_id,
prev_api_response,
app,
current_state,
)

api_response = make_api_request(headers=headers, **api_payload.__dict__)
Expand Down
1 change: 1 addition & 0 deletions llm-server/utils/make_api_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def make_api_request(
) -> Response:
try:
endpoint = replace_url_placeholders(endpoint, path_params)
print(f"Endpoint: {endpoint}")
url = servers[0] + endpoint
# Create a session and configure it with headers
session = requests.Session()
Expand Down

0 comments on commit 89653d2

Please sign in to comment.