-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 4d96fd7
Showing
8 changed files
with
2,333 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.pyc |
Large diffs are not rendered by default.
Oops, something went wrong.
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,5 @@ | ||
from .client import DBCLSLLMClient | ||
from .response import LLMResponse | ||
from .config import MODELS | ||
|
||
__all__ = ["DBCLSLLMClient", "LLMResponse", "MODELS", "TENANTS"] |
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,71 @@ | ||
import requests | ||
import logging | ||
|
||
# Configure logging | ||
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') | ||
|
||
class DBCLSLLMClient: | ||
BASE_URL = "https://llms.japaneast.cloudapp.azure.com/" | ||
VERSION = "0.0.2" | ||
def __init__(self, username, password, model_info=None): | ||
self.username = username | ||
self.password = password | ||
self.model_info = model_info or {} | ||
|
||
logging.info("Initialized DBCLSLLMClient with provided model_info.") | ||
|
||
def query(self, data, tenant=None, region=None): | ||
# Default tenant and region from model_info if not provided | ||
tenant = tenant or self.model_info.get('tenant') | ||
region = region or self.model_info.get('region') | ||
|
||
if 'model' not in self.model_info: | ||
logging.error("Model information is required but not provided.") | ||
raise ValueError("Model information is required but not provided.") | ||
|
||
# Construct the payload | ||
payload = { | ||
"model": self.model_info['model'], | ||
"data": data | ||
} | ||
|
||
if tenant: | ||
payload["tenant"] = tenant | ||
if region: | ||
payload["region"] = region | ||
|
||
logging.info("Sending request to %s with payload: %s", self.BASE_URL, payload) | ||
|
||
try: | ||
# Send the request | ||
response = requests.post( | ||
self.BASE_URL + self.model_info['class'], | ||
auth=(self.username, self.password), | ||
headers={"Content-type": "application/json"}, | ||
json=payload | ||
) | ||
|
||
# Raise an exception for HTTP errors | ||
response.raise_for_status() | ||
|
||
logging.info("Received response: %s", response.text) | ||
return LLMResponse(response.json()) | ||
|
||
except requests.exceptions.HTTPError as http_err: | ||
logging.error("HTTP error occurred: %s", http_err) | ||
raise | ||
except requests.exceptions.RequestException as req_err: | ||
logging.error("Error occurred during the request: %s", req_err) | ||
raise | ||
except Exception as err: | ||
logging.error("An unexpected error occurred: %s", err) | ||
raise | ||
|
||
class LLMResponse: | ||
def __init__(self, response_data): | ||
self.completion_tokens = response_data.get("completion_tokens") | ||
self.prompt_tokens = response_data.get("prompt_tokens") | ||
self.text = response_data.get("text") | ||
self.time_sec = response_data.get("time_sec") | ||
|
||
logging.debug("LLMResponse initialized with data: %s", response_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Configuration for available models and tenants | ||
|
||
MODELS = { | ||
"gpt-35-turbo": [ | ||
{"class": "gpt", "model": "gpt-35-turbo", "version": "0125", "tenant": "dbcls", "region": "northcentralus"}, | ||
{"class": "gpt", "model": "gpt-35-turbo", "version": "1106", "tenant": "dbcls", "region": "australiaeast"}, | ||
{"class": "gpt", "model": "gpt-35-turbo", "version": "0613", "tenant": "chiba", "region": "australiaeast"}, | ||
{"class": "gpt", "model": "gpt-35-turbo", "version": "0301", "tenant": "chiba", "region": "southcentralus"} | ||
], | ||
"gpt-4o": [ | ||
{"class": "gpt", "model": "gpt-4o", "version": "2024-05-13", "tenant": "dbcls", "region": "northcentralus"} | ||
], | ||
"gpt-4": [ | ||
{"class": "gpt", "model": "gpt-4", "version": "0125-Preview", "tenant": "dbcls", "region": "northcentralus"}, | ||
{"class": "gpt", "model": "gpt-4", "version": "1106-Preview", "tenant": "dbcls", "region": "australiaeast"}, | ||
{"class": "gpt", "model": "gpt-4", "version": "0613", "tenant": "chiba", "region": "australiaeast"} | ||
], | ||
"claude3": [ | ||
{"class": "claude3", "model": "opus"}, | ||
{"class": "claude3", "model": "sonnet5"}, | ||
{"class": "claude3", "model": "sonnet"}, | ||
{"class": "claude3", "model": "haiku"} | ||
], | ||
"commandr": [ | ||
{"class": "commandr", "model": "plus"}, | ||
{"class": "commandr", "model": "basic"} | ||
], | ||
"gemini": [ | ||
{"class": "gemini", "model": "1.5-pro"}, | ||
{"class": "gemini", "model": "1.5-flash"}, | ||
{"class": "gemini", "model": "1.0-pro"} | ||
], | ||
"llama": [ | ||
{"class": "llama", "model": "llama3-70b"}, | ||
{"class": "llama", "model": "llama3-8b"}, | ||
{"class": "llama", "model": "llama2-70b"}, | ||
{"class": "llama", "model": "llama2-13b"} | ||
], | ||
"mistral": [ | ||
{"class": "mistral", "model": "mistral-7b"}, | ||
{"class": "mistral", "model": "mixtral-8x7b"}, | ||
{"class": "mistral", "model": "mistral-large"} | ||
] | ||
} |
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,29 @@ | ||
class LLMResponse: | ||
def __init__(self, response_json: dict): | ||
""" | ||
Initialize the LLMResponse with the JSON response from the server. | ||
:param response_json: JSON response from the server. | ||
""" | ||
self.completion_tokens = response_json.get("completion_tokens", None) | ||
self.prompt_tokens = response_json.get("prompt_tokens", None) | ||
self.text = response_json.get("text", None) | ||
self.time_sec = response_json.get("time_sec", None) | ||
|
||
def __repr__(self): | ||
return (f"<LLMResponse completion_tokens={self.completion_tokens}, " | ||
f"prompt_tokens={self.prompt_tokens}, text={self.text}, " | ||
f"time_sec={self.time_sec}>") | ||
|
||
def to_dict(self): | ||
""" | ||
Convert the LLMResponse object to a dictionary. | ||
:return: A dictionary representation of the response. | ||
""" | ||
return { | ||
"completion_tokens": self.completion_tokens, | ||
"prompt_tokens": self.prompt_tokens, | ||
"text": self.text, | ||
"time_sec": self.time_sec | ||
} |
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,15 @@ | ||
from dbcls_llm.client import DBCLSLLMClient | ||
from dbcls_llm.config import MODELS | ||
|
||
# Initialize the client | ||
client = DBCLSLLMClient(username="*", password="*", model_info=MODELS["gpt-35-turbo"][0]) | ||
# Send a query to the LLM server | ||
response = client.query( | ||
data="Explain about Akt pathway" | ||
) | ||
|
||
# Access the response details | ||
print(response.text) # RESPONSE text | ||
print(response.completion_tokens) # 345 | ||
print(response.prompt_tokens) # 12 | ||
print(response.time_sec) # 3.624066114425659 |
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 @@ | ||
requests |