This repository has been archived by the owner on Jan 5, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 398
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 #124 from openchatai/custom_planner_3
Custom API Planner - Enhancements and Adjustments
- Loading branch information
Showing
20 changed files
with
426 additions
and
286 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
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
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
37 changes: 37 additions & 0 deletions
37
llm-server/routes/workflow/extractors/transform_api_response.py
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,37 @@ | ||
import os, logging | ||
from langchain.chat_models import ChatOpenAI | ||
from dotenv import load_dotenv | ||
from langchain.schema import HumanMessage, SystemMessage | ||
from typing import Any | ||
from routes.workflow.extractors.extract_json import extract_json_payload | ||
|
||
load_dotenv() | ||
|
||
openai_api_key = os.getenv("OPENAI_API_KEY") | ||
|
||
|
||
def transform_api_response_from_schema(server_url: str, api_response: str) -> str: | ||
chat = ChatOpenAI( | ||
openai_api_key=os.getenv("OPENAI_API_KEY"), | ||
model="gpt-3.5-turbo-16k", | ||
temperature=0, | ||
) | ||
|
||
messages = [ | ||
SystemMessage( | ||
content="You are a bot capable of comprehending API responses." | ||
), | ||
HumanMessage( | ||
content="Here is the response from current REST API: {} for endpoint: {}".format( | ||
api_response, server_url | ||
) | ||
), | ||
HumanMessage( | ||
content="Analyze the provided API responses and extract only the essential fields required for subsequent API interactions. Disregard any non-essential attributes such as CSS or color-related data. If there are generic fields like 'id,' provide them with more descriptive names in your response. Format your response as a JSON object with clear and meaningful keys that map to their respective values from the API response." | ||
), | ||
] | ||
|
||
result = chat(messages) | ||
logging.info("[OpenCopilot] Transformed Response: {}".format(result.content)) | ||
|
||
return result.content |
Oops, something went wrong.