-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve: tracking for invoke API breaking: Breaking change on the way connection setting happens breaking: update package name and repo name
- Loading branch information
1 parent
bcb8aa1
commit e6eda88
Showing
21 changed files
with
325 additions
and
69 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
from demo.openai_langchain import run_openai_agent | ||
# from demo.openai_langchain import run_openai_agent | ||
# | ||
# res = run_openai_agent() | ||
# print(str(res)) | ||
|
||
from demo.mockgpt_runnable_langchain import run_openai_agent | ||
|
||
res = run_openai_agent() | ||
print(str(res)) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import os | ||
|
||
|
||
api_key = os.environ.get("XPULSAI_API_KEY") | ||
host_url = os.environ.get("XPULSAI_HOST_URL", "https://api.xpuls.ai") | ||
adv_tracing_enabled = os.environ.get("XPULSAI_TRACING_ENABLED", "false") |
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 @@ | ||
from .xpuls_client import XpulsAIClient |
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,3 @@ | ||
XPULSAI_API_KEY = "XPULSAI_API_KEY" | ||
XPULSAI_HOST_URL = "XPULSAI_HOST_URL" | ||
XPULSAI_TRACING_ENABLED = "XPULSAI_TRACING_ENABLED" |
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,24 @@ | ||
from typing import List | ||
|
||
from pydantic import BaseModel | ||
|
||
|
||
class PromptVariable(BaseModel): | ||
variable: str | ||
default: str | ||
|
||
|
||
class PromptResponseData(BaseModel): | ||
prompt_version_id: str | ||
prompt_id: str | ||
prompt_external_id: str | ||
prompt: str | ||
prompt_variables: List[PromptVariable] | ||
|
||
|
||
class XPPrompt(BaseModel): | ||
prompt_version_id: str | ||
prompt_id: str | ||
prompt_external_id: str | ||
prompt: str | ||
|
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,57 @@ | ||
import os | ||
from typing import Optional | ||
|
||
import requests | ||
import time | ||
import logging | ||
|
||
import xpuls | ||
from xpuls.client import constants | ||
from xpuls.client.models import PromptResponseData | ||
|
||
|
||
class XpulsAIClient: | ||
def __init__(self): | ||
self._host_url = xpuls.host_url | ||
self._api_key = xpuls.api_key | ||
|
||
self._headers = {"XP-API-Key": self._api_key} | ||
|
||
def _make_request_with_retries(self, endpoint, method='GET', data=None, retries=3, backoff_factor=2): | ||
""" | ||
Make an API request with auto-retries and crashloop backoff. | ||
Supports GET, POST, PUT, and DELETE requests. | ||
""" | ||
if endpoint.startswith("/"): | ||
url = f"{self._host_url}/{endpoint[1:]}" | ||
else: | ||
url = f"{self._host_url}/{endpoint}" | ||
for attempt in range(retries): | ||
try: | ||
if method == 'GET': | ||
response = requests.get(url, headers=self._headers) | ||
elif method == 'POST': | ||
response = requests.post(url, headers=self._headers, json=data) | ||
elif method == 'PUT': | ||
response = requests.put(url, headers=self._headers, json=data) | ||
elif method == 'DELETE': | ||
response = requests.delete(url, headers=self._headers) | ||
else: | ||
raise ValueError("Unsupported HTTP method") | ||
|
||
response.raise_for_status() | ||
return response.json() | ||
except requests.RequestException as e: | ||
logging.warning(f"Request failed with error {e}, attempt {attempt + 1} of {retries}") | ||
time.sleep(backoff_factor ** attempt) | ||
|
||
raise Exception("Max retries exceeded") | ||
|
||
def get_live_prompt(self, prompt_id: str, env_name: str) -> PromptResponseData: | ||
data = self._make_request_with_retries( | ||
endpoint=f"/v1/prompt/{prompt_id}/env/{env_name}", | ||
method="GET", | ||
|
||
) | ||
|
||
return PromptResponseData(**data) |
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
Oops, something went wrong.