Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/routes/openai_route.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from fastapi import APIRouter, Depends, HTTPException
from src.providers import get_provider
from async_llm.providers import get_provider
from models.openai_request_models import ChatCompletionRequest , FunctionCallRequest
import json
import os
Expand Down
1 change: 1 addition & 0 deletions async_llm/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from async_llm import providers
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from src.providers.abstract_basellm import BaseLLMProvider
from async_llm.providers.abstract_basellm import BaseLLMProvider
import httpx
from typing import List, Dict
import json
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
from src.providers.abstract_basellm import BaseLLMProvider
from async_llm.providers.abstract_basellm import BaseLLMProvider
import httpx
from typing import List, Dict
import json
from urllib.parse import urljoin, urlencode

class GoogleProvider(BaseLLMProvider):
def __init__(self, api_key: str) -> None:
super().__init__()
base_url = "https://generativelanguage.googleapis.com/v1beta/"
endpoint = "models/gemini-1.5-flash:generateContent"
query_params = {"key": api_key}

self.base_url = urljoin(base_url, endpoint) + "?" + urlencode(query_params)
self.api_key = api_key
self.headers = {
"Content-Type": "application/json",
}

async def chat_completion(self, messages: List[Dict[str, str]]):
url = self.base_url
def _create_base_url(self, model:str="gemini-1.5-flash"):
base_url = "https://generativelanguage.googleapis.com/v1beta/"
endpoint = f"models/{model}:generateContent"
query_params = {"key": self.api_key}
base_url = urljoin(base_url, endpoint) + "?" + urlencode(query_params)
return base_url

async def chat_completion(self, model:str, messages: List[Dict[str, str]]):
self.model = model
url = self._create_base_url(model)
headers = self.headers
data = {
"contents": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from src.providers.abstract_basellm import BaseLLMProvider
from src.utils.pydantic_to_json import transform_schema
from async_llm.providers.abstract_basellm import BaseLLMProvider
from async_llm.utils.pydantic_to_json import transform_schema
import httpx
from typing import List , Dict
import json
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion examples/anthropic_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging
import os
from dotenv import load_dotenv
from src.providers import get_provider # Adjust this import based on your project structure
from async_llm.providers import get_provider # Adjust this import based on your project structure

logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion examples/openai_provider.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import asyncio
import os
from dotenv import load_dotenv
from src.providers import get_provider
from async_llm.providers import get_provider
import logging
from pydantic import BaseModel
import sys
Expand Down
26 changes: 26 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "async_llm"
version = "0.0.1"
description = "A Python package for asynchronous LLM integration."
readme = "README.md"
authors = [{ name = "Shamal De Silva", email = "shamalgithub@gmail.com" }, {name = "Sahan Ruwantha", email="sahanr.silva@proton.me"}]
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent"
]
dependencies = [
"fastapi>=0.112.2",
"httpx>=0.27.2",
"pydantic>=2.8.2",
"pytest>=8.3.2",
"python-dotenv>=1.0.1",
"setuptools>=58.1.0",
"pipreqs>=0.5.0",
"httpx[http2]>=0.27.2",
"pytest-asyncio>=0.24.0"
]
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from setuptools import setup , find_packages

setup(name="AsyncLLM" , version="0.0.1" , packages=find_packages())
setup(name="async_llm" , version="0.0.1" , packages=find_packages())
Empty file removed src/main.py
Empty file.
8 changes: 4 additions & 4 deletions test/test_chat_completion_test.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import pytest
import os
from dotenv import load_dotenv
from src.providers import get_provider
from src.providers.openai_provider import OpenAIProvider
from src.providers.anthropic_provider import ClaudeProvider
from src.providers.google_provider import GoogleProvider
from async_llm.providers import get_provider
from async_llm.providers.openai_provider import OpenAIProvider
from async_llm.providers.anthropic_provider import ClaudeProvider
from async_llm.providers.google_provider import GoogleProvider

load_dotenv()

Expand Down
5 changes: 3 additions & 2 deletions test/test_google.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from src.providers import get_provider
from async_llm.providers import get_provider
import os
from dotenv import load_dotenv
import pytest
Expand All @@ -7,10 +7,11 @@

@pytest.mark.asyncio
async def test_google_chat_completion():
model = "gemini-2.0-flash-exp"
messages = [
{"role": "user", "content": "What's the capital of France?"}
]
provider = get_provider("google", api_key=os.getenv("GOOGLE_API_KEY"))
result = await provider.chat_completion(messages=messages)
result = await provider.chat_completion(model=model, messages=messages)
print(result)
assert isinstance(result, dict)