Merge pull request #378 from tapas-joshi/v3

Made "llm_api_url" Optional: Not needed for default configurations
This commit is contained in:
Federico 2024-09-13 18:21:04 +02:00 committed by GitHub
commit 1405246270
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 32 additions and 20 deletions

View file

@ -1 +1,4 @@
MINIMUM_LOG_LEVEL="DEBUG"
# LOGGING
MINIMUM_LOG_LEVEL = "DEBUG"
MINIMUM_WAIT_TIME = 60 * 15

View file

@ -10,6 +10,7 @@ from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.by import By
import src.utils as utils
from app_config import MINIMUM_WAIT_TIME
from src.job import Job
from src.linkedIn_easy_applier import LinkedInEasyApplier
from loguru import logger
@ -78,7 +79,7 @@ class LinkedInJobManager:
searches = list(product(self.positions, self.locations))
random.shuffle(searches)
page_sleep = 0
minimum_time = 60 * 15
minimum_time = MINIMUM_WAIT_TIME
minimum_page_time = time.time() + minimum_time
for position, location in searches:

View file

@ -12,6 +12,7 @@ from typing import Union
import httpx
from Levenshtein import distance
from dotenv import load_dotenv
from langchain_core.messages import BaseMessage
from langchain_core.messages.ai import AIMessage
from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompt_values import StringPromptValue
@ -30,44 +31,50 @@ class AIModel(ABC):
class OpenAIModel(AIModel):
def __init__(self, api_key: str, llm_model: str, llm_api_url: str):
def __init__(self, api_key: str, llm_model: str):
from langchain_openai import ChatOpenAI
self.model = ChatOpenAI(model_name=llm_model, openai_api_key=api_key,
temperature=0.4, base_url=llm_api_url)
temperature=0.4)
def invoke(self, prompt: str) -> str:
def invoke(self, prompt: str) -> BaseMessage:
logger.debug("Invoking OpenAI API")
response = self.model.invoke(prompt)
return response
class ClaudeModel(AIModel):
def __init__(self, api_key: str, llm_model: str, llm_api_url: str):
def __init__(self, api_key: str, llm_model: str):
from langchain_anthropic import ChatAnthropic
self.model = ChatAnthropic(model=llm_model, api_key=api_key,
temperature=0.4, base_url=llm_api_url)
temperature=0.4)
def invoke(self, prompt: str) -> str:
def invoke(self, prompt: str) -> BaseMessage:
response = self.model.invoke(prompt)
logger.debug("Invoking Claude API")
return response
class OllamaModel(AIModel):
def __init__(self, api_key: str, llm_model: str, llm_api_url: str):
def __init__(self, llm_model: str, llm_api_url: str):
from langchain_ollama import ChatOllama
self.model = ChatOllama(model=llm_model, base_url=llm_api_url)
def invoke(self, prompt: str) -> str:
if len(llm_api_url) > 0:
logger.debug(f"Using Ollama with API URL: {llm_api_url}")
self.model = ChatOllama(model=llm_model, base_url=llm_api_url)
else:
self.model = ChatOllama(model=llm_model)
def invoke(self, prompt: str) -> BaseMessage:
response = self.model.invoke(prompt)
return response
class GeminiModel(AIModel):
def __init__(self, api_key:str, llm_model: str, llm_api_url: str):
def __init__(self, api_key:str, llm_model: str):
from langchain_google_genai import ChatGoogleGenerativeAI
self.model = ChatGoogleGenerativeAI(model=llm_model, google_api_key=api_key)
def invoke(self, prompt: str) -> str:
def invoke(self, prompt: str) -> BaseMessage:
response = self.model.invoke(prompt)
return response
@ -79,18 +86,19 @@ class AIAdapter:
def _create_model(self, config: dict, api_key: str) -> AIModel:
llm_model_type = config['llm_model_type']
llm_model = config['llm_model']
llm_api_url = config['llm_api_url']
logger.debug('Using {0} with {1} from {2}'.format(
llm_model_type, llm_model, llm_api_url))
llm_api_url = config.get('llm_api_url', "")
logger.debug(f"Using {llm_model_type} with {llm_model}")
if llm_model_type == "openai":
return OpenAIModel(api_key, llm_model, llm_api_url)
return OpenAIModel(api_key, llm_model)
elif llm_model_type == "claude":
return ClaudeModel(api_key, llm_model, llm_api_url)
return ClaudeModel(api_key, llm_model)
elif llm_model_type == "ollama":
return OllamaModel(api_key, llm_model, llm_api_url)
return OllamaModel(llm_model, llm_api_url)
elif llm_model_type == "gemini":
return GeminiModel(api_key, llm_model, llm_api_url)
return GeminiModel(api_key, llm_model)
else:
raise ValueError(f"Unsupported model type: {llm_model_type}")