Skip to content

Commit b39bddd

Browse files
hallacykennyhsu5madeleineth
authored
Hallacy/11 4 release (#54)
* Make embeddings_utils be importable (#104) * Make embeddings_utils be importable * Small tweaks to dicts for typing * Remove default api_prefix and move v1 prefix to default api_base (#95) * make construct_from key argument optional (#92) * Split search.prepare_data into answers/classifications/search versions (#93) * Break out prepare_data into answers, classifications, and search * And cleaned up CLI * Validate search files (#69) * Add validators for search files * Clean up fields Co-authored-by: kennyhsu5 <[email protected]> Co-authored-by: Madeleine Thompson <[email protected]>
1 parent 88bbe08 commit b39bddd

19 files changed

+246
-115
lines changed

examples/embeddings/Classification.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
}
9191
],
9292
"source": [
93-
"from utils import plot_multiclass_precision_recall\n",
93+
"from openai.embeddings_utils import plot_multiclass_precision_recall\n",
9494
"\n",
9595
"plot_multiclass_precision_recall(probas, y_test, [1,2,3,4,5], clf)"
9696
]

examples/embeddings/Code_search.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@
185185
}
186186
],
187187
"source": [
188-
"from utils import get_embedding\n",
188+
"from openai.embeddings_utils import get_embedding\n",
189189
"\n",
190190
"df = pd.DataFrame(all_funcs)\n",
191191
"df['code_embedding'] = df['code'].apply(lambda x: get_embedding(x, engine='babbage-code-search-code'))\n",
@@ -231,7 +231,7 @@
231231
}
232232
],
233233
"source": [
234-
"from utils import cosine_similarity\n",
234+
"from openai.embeddings_utils import cosine_similarity\n",
235235
"\n",
236236
"def search_functions(df, code_query, n=3, pprint=True, n_lines=7):\n",
237237
" embedding = get_embedding(code_query, engine='babbage-code-search-text')\n",

examples/embeddings/Obtain_dataset.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@
156156
"metadata": {},
157157
"outputs": [],
158158
"source": [
159-
"from utils import get_embedding\n",
159+
"from openai.embeddings_utils import get_embedding\n",
160160
"\n",
161161
"# This will take just under 10 minutes\n",
162162
"df['babbage_similarity'] = df.combined.apply(lambda x: get_embedding(x, engine='babbage-similarity'))\n",

examples/embeddings/Semantic_text_search_using_embeddings.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
}
5050
],
5151
"source": [
52-
"from utils import get_embedding, cosine_similarity\n",
52+
"from openai.embeddings_utils import get_embedding, cosine_similarity\n",
5353
"\n",
5454
"# search through the reviews for a specific product\n",
5555
"def search_reviews(df, product_description, n=3, pprint=True):\n",

examples/embeddings/User_and_product_embeddings.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
"metadata": {},
7171
"outputs": [],
7272
"source": [
73-
"from utils import cosine_similarity\n",
73+
"from openai.embeddings_utils import cosine_similarity\n",
7474
"\n",
7575
"# evaluate embeddings as recommendations on X_test\n",
7676
"def evaluate_single_match(row):\n",

examples/embeddings/Zero-shot_classification.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
}
7979
],
8080
"source": [
81-
"from utils import cosine_similarity, get_embedding\n",
81+
"from openai.embeddings_utils import cosine_similarity, get_embedding\n",
8282
"from sklearn.metrics import PrecisionRecallDisplay\n",
8383
"\n",
8484
"def evaluate_emeddings_approach(\n",

openai/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
api_key_path: Optional[str] = os.environ.get("OPENAI_API_KEY_PATH")
2626

2727
organization = os.environ.get("OPENAI_ORGANIZATION")
28-
api_base = os.environ.get("OPENAI_API_BASE", "https://api.openai.com")
28+
api_base = os.environ.get("OPENAI_API_BASE", "https://api.openai.com/v1")
2929
api_version = None
3030
verify_ssl_certs = True # No effect. Certificates are always verified.
3131
proxy = None

openai/api_resources/abstract/api_resource.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66

77
class APIResource(OpenAIObject):
8-
api_prefix = "v1"
8+
api_prefix = ""
99

1010
@classmethod
1111
def retrieve(cls, id, api_key=None, request_id=None, **params):
@@ -28,7 +28,9 @@ def class_url(cls):
2828
# Namespaces are separated in object names with periods (.) and in URLs
2929
# with forward slashes (/), so replace the former with the latter.
3030
base = cls.OBJECT_NAME.replace(".", "/") # type: ignore
31-
return "/%s/%ss" % (cls.api_prefix, base)
31+
if cls.api_prefix:
32+
return "/%s/%ss" % (cls.api_prefix, base)
33+
return "/%ss" % (base)
3234

3335
def instance_url(self):
3436
id = self.get("id")

openai/api_resources/abstract/engine_api_resource.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ def class_url(cls, engine: Optional[str] = None):
2222
# with forward slashes (/), so replace the former with the latter.
2323
base = cls.OBJECT_NAME.replace(".", "/") # type: ignore
2424
if engine is None:
25-
return "/%s/%ss" % (cls.api_prefix, base)
25+
return "/%ss" % (base)
2626

2727
extn = quote_plus(engine)
28-
return "/%s/engines/%s/%ss" % (cls.api_prefix, extn, base)
28+
return "/engines/%s/%ss" % (extn, base)
2929

3030
@classmethod
3131
def create(

openai/api_resources/answer.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22

33

44
class Answer(OpenAIObject):
5-
api_prefix = "v1"
6-
75
@classmethod
8-
def get_url(self, base):
9-
return "/%s/%s" % (self.api_prefix, base)
6+
def get_url(self):
7+
return "/answers"
108

119
@classmethod
1210
def create(cls, **params):
1311
instance = cls()
14-
return instance.request("post", cls.get_url("answers"), params)
12+
return instance.request("post", cls.get_url(), params)

0 commit comments

Comments
 (0)