Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support openai use proxy address #51

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
7 changes: 6 additions & 1 deletion needlehaystack/evaluators/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,15 @@ def __init__(self,
if (not api_key):
raise ValueError("NIAH_EVALUATOR_API_KEY must be in env for using openai evaluator.")

self.api_key = api_key
api_base = os.getenv("NIAH_MODEL_API_BASE")
if api_base is None:
api_base = f"https://api.openai.com/v1"

self.api_key = api_key
self.api_base = api_base
self.evaluator = ChatOpenAI(model=self.model_name,
openai_api_key=self.api_key,
openai_api_base=self.api_base,
**self.model_kwargs)

def evaluate_response(self, response: str) -> int:
Expand Down
7 changes: 6 additions & 1 deletion needlehaystack/providers/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,15 @@ def __init__(self,
if (not api_key):
raise ValueError("NIAH_MODEL_API_KEY must be in env.")

api_base = os.getenv("NIAH_MODEL_API_BASE")
if api_base is None:
api_base = f"https://api.openai.com/v1"

self.model_name = model_name
self.model_kwargs = model_kwargs
self.api_key = api_key
self.model = AsyncOpenAI(api_key=self.api_key)
self.api_base = api_base
self.model = AsyncOpenAI(api_key=self.api_key, base_url=self.api_base)
self.tokenizer = tiktoken.encoding_for_model(self.model_name)

async def evaluate_model(self, prompt: str) -> str:
Expand Down