| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 88bbe08 commit b39bddd
19 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -90,7 +90,7 @@ | |||
| 90 | 90 | } | |
| 91 | 91 | ], | |
| 92 | 92 | "source": [ | |
| 93 | - "from utils import plot_multiclass_precision_recall\n", | ||
| 93 | + "from openai.embeddings_utils import plot_multiclass_precision_recall\n", | ||
| 94 | 94 | "\n", | |
| 95 | 95 | "plot_multiclass_precision_recall(probas, y_test, [1,2,3,4,5], clf)" | |
| 96 | 96 | ] | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -185,7 +185,7 @@ | |||
| 185 | 185 | } | |
| 186 | 186 | ], | |
| 187 | 187 | "source": [ | |
| 188 | - "from utils import get_embedding\n", | ||
| 188 | + "from openai.embeddings_utils import get_embedding\n", | ||
| 189 | 189 | "\n", | |
| 190 | 190 | "df = pd.DataFrame(all_funcs)\n", | |
| 191 | 191 | "df['code_embedding'] = df['code'].apply(lambda x: get_embedding(x, engine='babbage-code-search-code'))\n", | |
@@ -231,7 +231,7 @@ | |||
| 231 | 231 | } | |
| 232 | 232 | ], | |
| 233 | 233 | "source": [ | |
| 234 | - "from utils import cosine_similarity\n", | ||
| 234 | + "from openai.embeddings_utils import cosine_similarity\n", | ||
| 235 | 235 | "\n", | |
| 236 | 236 | "def search_functions(df, code_query, n=3, pprint=True, n_lines=7):\n", | |
| 237 | 237 | " embedding = get_embedding(code_query, engine='babbage-code-search-text')\n", | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -156,7 +156,7 @@ | |||
| 156 | 156 | "metadata": {}, | |
| 157 | 157 | "outputs": [], | |
| 158 | 158 | "source": [ | |
| 159 | - "from utils import get_embedding\n", | ||
| 159 | + "from openai.embeddings_utils import get_embedding\n", | ||
| 160 | 160 | "\n", | |
| 161 | 161 | "# This will take just under 10 minutes\n", | |
| 162 | 162 | "df['babbage_similarity'] = df.combined.apply(lambda x: get_embedding(x, engine='babbage-similarity'))\n", | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -49,7 +49,7 @@ | |||
| 49 | 49 | } | |
| 50 | 50 | ], | |
| 51 | 51 | "source": [ | |
| 52 | - "from utils import get_embedding, cosine_similarity\n", | ||
| 52 | + "from openai.embeddings_utils import get_embedding, cosine_similarity\n", | ||
| 53 | 53 | "\n", | |
| 54 | 54 | "# search through the reviews for a specific product\n", | |
| 55 | 55 | "def search_reviews(df, product_description, n=3, pprint=True):\n", | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -70,7 +70,7 @@ | |||
| 70 | 70 | "metadata": {}, | |
| 71 | 71 | "outputs": [], | |
| 72 | 72 | "source": [ | |
| 73 | - "from utils import cosine_similarity\n", | ||
| 73 | + "from openai.embeddings_utils import cosine_similarity\n", | ||
| 74 | 74 | "\n", | |
| 75 | 75 | "# evaluate embeddings as recommendations on X_test\n", | |
| 76 | 76 | "def evaluate_single_match(row):\n", | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -78,7 +78,7 @@ | |||
| 78 | 78 | } | |
| 79 | 79 | ], | |
| 80 | 80 | "source": [ | |
| 81 | - "from utils import cosine_similarity, get_embedding\n", | ||
| 81 | + "from openai.embeddings_utils import cosine_similarity, get_embedding\n", | ||
| 82 | 82 | "from sklearn.metrics import PrecisionRecallDisplay\n", | |
| 83 | 83 | "\n", | |
| 84 | 84 | "def evaluate_emeddings_approach(\n", | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -25,7 +25,7 @@ | |||
| 25 | 25 | api_key_path: Optional[str] = os.environ.get("OPENAI_API_KEY_PATH") | |
| 26 | 26 | ||
| 27 | 27 | 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") | ||
| 29 | 29 | api_version = None | |
| 30 | 30 | verify_ssl_certs = True # No effect. Certificates are always verified. | |
| 31 | 31 | proxy = None | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,7 +5,7 @@ | |||
| 5 | 5 | ||
| 6 | 6 | ||
| 7 | 7 | class APIResource(OpenAIObject): | |
| 8 | - api_prefix = "v1" | ||
| 8 | + api_prefix = "" | ||
| 9 | 9 | ||
| 10 | 10 | @classmethod | |
| 11 | 11 | def retrieve(cls, id, api_key=None, request_id=None, **params): | |
@@ -28,7 +28,9 @@ def class_url(cls): | |||
| 28 | 28 | # Namespaces are separated in object names with periods (.) and in URLs | |
| 29 | 29 | # with forward slashes (/), so replace the former with the latter. | |
| 30 | 30 | 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) | ||
| 32 | 34 | ||
| 33 | 35 | def instance_url(self): | |
| 34 | 36 | id = self.get("id") | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -22,10 +22,10 @@ def class_url(cls, engine: Optional[str] = None): | |||
| 22 | 22 | # with forward slashes (/), so replace the former with the latter. | |
| 23 | 23 | base = cls.OBJECT_NAME.replace(".", "/") # type: ignore | |
| 24 | 24 | if engine is None: | |
| 25 | - return "/%s/%ss" % (cls.api_prefix, base) | ||
| 25 | + return "/%ss" % (base) | ||
| 26 | 26 | ||
| 27 | 27 | extn = quote_plus(engine) | |
| 28 | - return "/%s/engines/%s/%ss" % (cls.api_prefix, extn, base) | ||
| 28 | + return "/engines/%s/%ss" % (extn, base) | ||
| 29 | 29 | ||
| 30 | 30 | @classmethod | |
| 31 | 31 | def create( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,13 +2,11 @@ | |||
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | 4 | class Answer(OpenAIObject): | |
| 5 | - api_prefix = "v1" | ||
| 6 | - | ||
| 7 | 5 | @classmethod | |
| 8 | - def get_url(self, base): | ||
| 9 | - return "/%s/%s" % (self.api_prefix, base) | ||
| 6 | + def get_url(self): | ||
| 7 | + return "/answers" | ||
| 10 | 8 | ||
| 11 | 9 | @classmethod | |
| 12 | 10 | def create(cls, **params): | |
| 13 | 11 | instance = cls() | |
| 14 | - return instance.request("post", cls.get_url("answers"), params) | ||
| 12 | + return instance.request("post", cls.get_url(), params) | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments