Refactor/collect embeddings code (#3060)

* Collect all embedding code into a single module

* Collect all embedding code into a single module

* actually, llm_utils is a better place

* Oh, and remove the module now that we don't use it

---------

Co-authored-by: Nicholas Tindle <nick@ntindle.com>
pull/3061/head^2
James Collins 2023-04-23 15:50:50 -07:00 committed by GitHub
parent 374f543bea
commit aedd288dbe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 12 additions and 19 deletions

View File

@ -154,6 +154,13 @@ def create_chat_completion(
return resp
def get_ada_embedding(text):
text = text.replace("\n", " ")
return api_manager.embedding_create(
text_list=[text], model="text-embedding-ada-002"
)
def create_embedding_with_ada(text) -> list:
"""Create an embedding with text-ada-002 using the OpenAI SDK"""
num_retries = 10

View File

@ -1,21 +1,11 @@
"""Base class for memory providers."""
import abc
import openai
from autogpt.api_manager import api_manager
from autogpt.config import AbstractSingleton, Config
cfg = Config()
def get_ada_embedding(text):
text = text.replace("\n", " ")
return api_manager.embedding_create(
text_list=[text], model="text-embedding-ada-002"
)
class MemoryProviderSingleton(AbstractSingleton):
@abc.abstractmethod
def add(self, data):

View File

@ -4,7 +4,8 @@ import re
from pymilvus import Collection, CollectionSchema, DataType, FieldSchema, connections
from autogpt.config import Config
from autogpt.memory.base import MemoryProviderSingleton, get_ada_embedding
from autogpt.llm_utils import get_ada_embedding
from autogpt.memory.base import MemoryProviderSingleton
class MilvusMemory(MemoryProviderSingleton):

View File

@ -1,12 +1,10 @@
import uuid
import weaviate
from weaviate import Client
from weaviate.embedded import EmbeddedOptions
from weaviate.util import generate_uuid5
from autogpt.config import Config
from autogpt.memory.base import MemoryProviderSingleton, get_ada_embedding
from autogpt.llm_utils import get_ada_embedding
from autogpt.memory.base import MemoryProviderSingleton
def default_schema(weaviate_index):

View File

@ -1,14 +1,11 @@
import os
import sys
import unittest
from unittest import mock
from uuid import uuid4
from weaviate import Client
from weaviate.util import get_valid_uuid
from autogpt.config import Config
from autogpt.memory.base import get_ada_embedding
from autogpt.llm_utils import get_ada_embedding
from autogpt.memory.weaviate import WeaviateMemory