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

Attributes #95

Merged
merged 4 commits into from
Jun 8, 2024
Merged
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
24 changes: 13 additions & 11 deletions skllm/llm/gpt/mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,20 @@ def _set_keys(self, key: Optional[str] = None, org: Optional[str] = None) -> Non
"""
Set the OpenAI key and organization.
"""
self.openai_key = key
self.openai_org = org

self.key = key
self.org = org


def _get_openai_key(self) -> str:
"""
Get the OpenAI key from the class or the config file.

Returns
-------
openai_key: str
key: str
"""
key = self.openai_key
key = self.key
if key is None:
key = _Config.get_openai_key()
if key is None:
Expand All @@ -90,14 +92,14 @@ def _get_openai_org(self) -> str:

Returns
-------
openai_org: str
org: str
"""
key = self.openai_org
if key is None:
key = _Config.get_openai_org()
if key is None:
org = self.org
if org is None:
org = _Config.get_openai_org()
if org is None:
raise RuntimeError("OpenAI organization was not found")
return key
return org


class GPTTextCompletionMixin(GPTMixin, BaseTextCompletionMixin):
Expand Down Expand Up @@ -262,4 +264,4 @@ def _tune(self, X, y):
self.openai_model = job.fine_tuned_model
self.model = self.openai_model # openai_model is probably not required anymore
delete_file(client, job.training_file)
print(f"Finished training.")
print(f"Finished training.")
2 changes: 1 addition & 1 deletion skllm/models/gpt/classification/few_shot.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def __init__(
metric used for similarity search, by default "euclidean"
"""
if vectorizer is None:
vectorizer = GPTVectorizer(model="text-embedding-ada-002")
vectorizer = GPTVectorizer(model="text-embedding-ada-002", key=key, org=org)
super().__init__(
model=model,
default_label=default_label,
Expand Down
Loading