Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkall authored Jun 11, 2024
2 parents 735cf34 + bf7e4d6 commit 6a57096
Show file tree
Hide file tree
Showing 100 changed files with 3,744 additions and 424 deletions.
4 changes: 2 additions & 2 deletions OAI_CONFIG_LIST_sample
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
"api_key": "<your Azure OpenAI API key here>",
"base_url": "<your Azure OpenAI API base here>",
"api_type": "azure",
"api_version": "2024-02-15-preview"
"api_version": "2024-02-01"
},
{
"model": "<your Azure OpenAI deployment name>",
"api_key": "<your Azure OpenAI API key here>",
"base_url": "<your Azure OpenAI API base here>",
"api_type": "azure",
"api_version": "2024-02-15-preview"
"api_version": "2024-02-01"
}
]
84 changes: 38 additions & 46 deletions autogen/agentchat/contrib/vectordb/pgvectordb.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ class Collection:
client: The PGVector client.
collection_name (str): The name of the collection. Default is "documents".
embedding_function (Callable): The embedding function used to generate the vector representation.
Default is None. SentenceTransformer("all-MiniLM-L6-v2").encode will be used when None.
Models can be chosen from:
https://huggingface.co/models?library=sentence-transformers
metadata (Optional[dict]): The metadata of the collection.
get_or_create (Optional): The flag indicating whether to get or create the collection.
model_name: (Optional str) | Sentence embedding model to use. Models can be chosen from:
https://huggingface.co/models?library=sentence-transformers
"""

def __init__(
Expand All @@ -45,7 +46,6 @@ def __init__(
embedding_function: Callable = None,
metadata=None,
get_or_create=None,
model_name="all-MiniLM-L6-v2",
):
"""
Initialize the Collection object.
Expand All @@ -56,30 +56,26 @@ def __init__(
embedding_function: The embedding function used to generate the vector representation.
metadata: The metadata of the collection.
get_or_create: The flag indicating whether to get or create the collection.
model_name: | Sentence embedding model to use. Models can be chosen from:
https://huggingface.co/models?library=sentence-transformers
Returns:
None
"""
self.client = client
self.embedding_function = embedding_function
self.model_name = model_name
self.name = self.set_collection_name(collection_name)
self.require_embeddings_or_documents = False
self.ids = []
try:
self.embedding_function = (
SentenceTransformer(self.model_name) if embedding_function is None else embedding_function
)
except Exception as e:
logger.error(
f"Validate the model name entered: {self.model_name} "
f"from https://huggingface.co/models?library=sentence-transformers\nError: {e}"
)
raise e
if embedding_function:
self.embedding_function = embedding_function
else:
self.embedding_function = SentenceTransformer("all-MiniLM-L6-v2").encode
self.metadata = metadata if metadata else {"hnsw:space": "ip", "hnsw:construction_ef": 32, "hnsw:M": 16}
self.documents = ""
self.get_or_create = get_or_create
# This will get the model dimension size by computing the embeddings dimensions
sentences = [
"The weather is lovely today in paradise.",
]
embeddings = self.embedding_function(sentences)
self.dimension = len(embeddings[0])

def set_collection_name(self, collection_name) -> str:
name = re.sub("-", "_", collection_name)
Expand Down Expand Up @@ -115,14 +111,14 @@ def add(self, ids: List[ItemID], documents: List, embeddings: List = None, metad
elif metadatas is not None:
for doc_id, metadata, document in zip(ids, metadatas, documents):
metadata = re.sub("'", '"', str(metadata))
embedding = self.embedding_function.encode(document)
embedding = self.embedding_function(document)
sql_values.append((doc_id, metadata, embedding, document))
sql_string = (
f"INSERT INTO {self.name} (id, metadatas, embedding, documents)\n" f"VALUES (%s, %s, %s, %s);\n"
)
else:
for doc_id, document in zip(ids, documents):
embedding = self.embedding_function.encode(document)
embedding = self.embedding_function(document)
sql_values.append((doc_id, document, embedding))
sql_string = f"INSERT INTO {self.name} (id, documents, embedding)\n" f"VALUES (%s, %s, %s);\n"
logger.debug(f"Add SQL String:\n{sql_string}\n{sql_values}")
Expand Down Expand Up @@ -166,7 +162,7 @@ def upsert(self, ids: List[ItemID], documents: List, embeddings: List = None, me
elif metadatas is not None:
for doc_id, metadata, document in zip(ids, metadatas, documents):
metadata = re.sub("'", '"', str(metadata))
embedding = self.embedding_function.encode(document)
embedding = self.embedding_function(document)
sql_values.append((doc_id, metadata, embedding, document, metadata, document, embedding))
sql_string = (
f"INSERT INTO {self.name} (id, metadatas, embedding, documents)\n"
Expand All @@ -176,7 +172,7 @@ def upsert(self, ids: List[ItemID], documents: List, embeddings: List = None, me
)
else:
for doc_id, document in zip(ids, documents):
embedding = self.embedding_function.encode(document)
embedding = self.embedding_function(document)
sql_values.append((doc_id, document, embedding, document))
sql_string = (
f"INSERT INTO {self.name} (id, documents, embedding)\n"
Expand Down Expand Up @@ -304,7 +300,7 @@ def get(
)
except (psycopg.errors.UndefinedTable, psycopg.errors.UndefinedColumn) as e:
logger.info(f"Error executing select on non-existent table: {self.name}. Creating it instead. Error: {e}")
self.create_collection(collection_name=self.name)
self.create_collection(collection_name=self.name, dimension=self.dimension)
logger.info(f"Created table {self.name}")

cursor.close()
Expand Down Expand Up @@ -419,7 +415,7 @@ def query(
cursor = self.client.cursor()
results = []
for query_text in query_texts:
vector = self.embedding_function.encode(query_text, convert_to_tensor=False).tolist()
vector = self.embedding_function(query_text, convert_to_tensor=False).tolist()
if distance_type.lower() == "cosine":
index_function = "<=>"
elif distance_type.lower() == "euclidean":
Expand Down Expand Up @@ -526,22 +522,31 @@ def delete_collection(self, collection_name: Optional[str] = None) -> None:
cursor.execute(f"DROP TABLE IF EXISTS {self.name}")
cursor.close()

def create_collection(self, collection_name: Optional[str] = None) -> None:
def create_collection(
self, collection_name: Optional[str] = None, dimension: Optional[Union[str, int]] = None
) -> None:
"""
Create a new collection.
Args:
collection_name (Optional[str]): The name of the new collection.
dimension (Optional[Union[str, int]]): The dimension size of the sentence embedding model
Returns:
None
"""
if collection_name:
self.name = collection_name

if dimension:
self.dimension = dimension
elif self.dimension is None:
self.dimension = 384

cursor = self.client.cursor()
cursor.execute(
f"CREATE TABLE {self.name} ("
f"documents text, id CHAR(8) PRIMARY KEY, metadatas JSONB, embedding vector(384));"
f"documents text, id CHAR(8) PRIMARY KEY, metadatas JSONB, embedding vector({self.dimension}));"
f"CREATE INDEX "
f'ON {self.name} USING hnsw (embedding vector_l2_ops) WITH (m = {self.metadata["hnsw:M"]}, '
f'ef_construction = {self.metadata["hnsw:construction_ef"]});'
Expand Down Expand Up @@ -573,7 +578,6 @@ def __init__(
connect_timeout: Optional[int] = 10,
embedding_function: Callable = None,
metadata: Optional[dict] = None,
model_name: Optional[str] = "all-MiniLM-L6-v2",
) -> None:
"""
Initialize the vector database.
Expand All @@ -591,15 +595,14 @@ def __init__(
username: str | The database username to use. Default is None.
password: str | The database user password to use. Default is None.
connect_timeout: int | The timeout to set for the connection. Default is 10.
embedding_function: Callable | The embedding function used to generate the vector representation
of the documents. Default is None.
embedding_function: Callable | The embedding function used to generate the vector representation.
Default is None. SentenceTransformer("all-MiniLM-L6-v2").encode will be used when None.
Models can be chosen from:
https://huggingface.co/models?library=sentence-transformers
metadata: dict | The metadata of the vector database. Default is None. If None, it will use this
setting: {"hnsw:space": "ip", "hnsw:construction_ef": 30, "hnsw:M": 16}. Creates Index on table
using hnsw (embedding vector_l2_ops) WITH (m = hnsw:M) ef_construction = "hnsw:construction_ef".
For more info: https://github.com/pgvector/pgvector?tab=readme-ov-file#hnsw
model_name: str | Sentence embedding model to use. Models can be chosen from:
https://huggingface.co/models?library=sentence-transformers
Returns:
None
"""
Expand All @@ -613,17 +616,10 @@ def __init__(
password=password,
connect_timeout=connect_timeout,
)
self.model_name = model_name
try:
self.embedding_function = (
SentenceTransformer(self.model_name) if embedding_function is None else embedding_function
)
except Exception as e:
logger.error(
f"Validate the model name entered: {self.model_name} "
f"from https://huggingface.co/models?library=sentence-transformers\nError: {e}"
)
raise e
if embedding_function:
self.embedding_function = embedding_function
else:
self.embedding_function = SentenceTransformer("all-MiniLM-L6-v2").encode
self.metadata = metadata
register_vector(self.client)
self.active_collection = None
Expand Down Expand Up @@ -738,7 +734,6 @@ def create_collection(
embedding_function=self.embedding_function,
get_or_create=get_or_create,
metadata=self.metadata,
model_name=self.model_name,
)
collection.set_collection_name(collection_name=collection_name)
collection.create_collection(collection_name=collection_name)
Expand All @@ -751,7 +746,6 @@ def create_collection(
embedding_function=self.embedding_function,
get_or_create=get_or_create,
metadata=self.metadata,
model_name=self.model_name,
)
collection.set_collection_name(collection_name=collection_name)
collection.create_collection(collection_name=collection_name)
Expand All @@ -765,7 +759,6 @@ def create_collection(
embedding_function=self.embedding_function,
get_or_create=get_or_create,
metadata=self.metadata,
model_name=self.model_name,
)
collection.set_collection_name(collection_name=collection_name)
collection.create_collection(collection_name=collection_name)
Expand Down Expand Up @@ -797,7 +790,6 @@ def get_collection(self, collection_name: str = None) -> Collection:
client=self.client,
collection_name=collection_name,
embedding_function=self.embedding_function,
model_name=self.model_name,
)
return self.active_collection

Expand Down
4 changes: 2 additions & 2 deletions autogen/oai/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ def __init__(self, *, config_list: Optional[List[Dict[str, Any]]] = None, **base
"api_key": os.environ.get("AZURE_OPENAI_API_KEY"),
"api_type": "azure",
"base_url": os.environ.get("AZURE_OPENAI_API_BASE"),
"api_version": "2024-02-15-preview",
"api_version": "2024-02-01",
},
{
"model": "gpt-3.5-turbo",
Expand Down Expand Up @@ -559,7 +559,7 @@ def yes_or_no_filter(context, response):
```
- allow_format_str_template (bool | None): Whether to allow format string template in the config. Default to false.
- api_version (str | None): The api version. Default to None. E.g., "2024-02-15-preview".
- api_version (str | None): The api version. Default to None. E.g., "2024-02-01".
Raises:
- RuntimeError: If all declared custom model clients are not registered
- APIError: If any model client create call raises an APIError
Expand Down
2 changes: 1 addition & 1 deletion autogen/oai/completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ def create(
"api_key": os.environ.get("AZURE_OPENAI_API_KEY"),
"api_type": "azure",
"base_url": os.environ.get("AZURE_OPENAI_API_BASE"),
"api_version": "2024-02-15-preview",
"api_version": "2024-02-01",
},
{
"model": "gpt-3.5-turbo",
Expand Down
4 changes: 2 additions & 2 deletions autogen/oai/openai_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from packaging.version import parse

NON_CACHE_KEY = ["api_key", "base_url", "api_type", "api_version", "azure_ad_token", "azure_ad_token_provider"]
DEFAULT_AZURE_API_VERSION = "2024-02-15-preview"
DEFAULT_AZURE_API_VERSION = "2024-02-01"
OAI_PRICE1K = {
# https://openai.com/api/pricing/
# gpt-4o
Expand Down Expand Up @@ -127,7 +127,7 @@ def get_config_list(
# Optionally, define the API type and version if they are common for all keys
api_type = 'azure'
api_version = '2024-02-15-preview'
api_version = '2024-02-01'
# Call the get_config_list function to get a list of configuration dictionaries
config_list = get_config_list(api_keys, base_urls, api_type, api_version)
Expand Down
2 changes: 1 addition & 1 deletion autogen/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.2.28"
__version__ = "0.2.29"
20 changes: 20 additions & 0 deletions dotnet/AutoGen.sln
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoGen.Anthropic.Tests", "
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoGen.Anthropic.Samples", "sample\AutoGen.Anthropic.Samples\AutoGen.Anthropic.Samples.csproj", "{834B4E85-64E5-4382-8465-548F332E5298}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoGen.Gemini", "src\AutoGen.Gemini\AutoGen.Gemini.csproj", "{EFE0DC86-80FC-4D52-95B7-07654BA1A769}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoGen.Gemini.Tests", "test\AutoGen.Gemini.Tests\AutoGen.Gemini.Tests.csproj", "{8EA16BAB-465A-4C07-ABC4-1070D40067E9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoGen.Gemini.Sample", "sample\AutoGen.Gemini.Sample\AutoGen.Gemini.Sample.csproj", "{19679B75-CE3A-4DF0-A3F0-CA369D2760A4}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoGen.AotCompatibility.Tests", "test\AutoGen.AotCompatibility.Tests\AutoGen.AotCompatibility.Tests.csproj", "{6B82F26D-5040-4453-B21B-C8D1F913CE4C}"
EndProject
Global
Expand Down Expand Up @@ -149,6 +154,18 @@ Global
{834B4E85-64E5-4382-8465-548F332E5298}.Debug|Any CPU.Build.0 = Debug|Any CPU
{834B4E85-64E5-4382-8465-548F332E5298}.Release|Any CPU.ActiveCfg = Release|Any CPU
{834B4E85-64E5-4382-8465-548F332E5298}.Release|Any CPU.Build.0 = Release|Any CPU
{EFE0DC86-80FC-4D52-95B7-07654BA1A769}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EFE0DC86-80FC-4D52-95B7-07654BA1A769}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EFE0DC86-80FC-4D52-95B7-07654BA1A769}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EFE0DC86-80FC-4D52-95B7-07654BA1A769}.Release|Any CPU.Build.0 = Release|Any CPU
{8EA16BAB-465A-4C07-ABC4-1070D40067E9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8EA16BAB-465A-4C07-ABC4-1070D40067E9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8EA16BAB-465A-4C07-ABC4-1070D40067E9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8EA16BAB-465A-4C07-ABC4-1070D40067E9}.Release|Any CPU.Build.0 = Release|Any CPU
{19679B75-CE3A-4DF0-A3F0-CA369D2760A4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{19679B75-CE3A-4DF0-A3F0-CA369D2760A4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{19679B75-CE3A-4DF0-A3F0-CA369D2760A4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{19679B75-CE3A-4DF0-A3F0-CA369D2760A4}.Release|Any CPU.Build.0 = Release|Any CPU
{6B82F26D-5040-4453-B21B-C8D1F913CE4C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6B82F26D-5040-4453-B21B-C8D1F913CE4C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6B82F26D-5040-4453-B21B-C8D1F913CE4C}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -180,6 +197,9 @@ Global
{6A95E113-B824-4524-8F13-CD0C3E1C8804} = {18BF8DD7-0585-48BF-8F97-AD333080CE06}
{815E937E-86D6-4476-9EC6-B7FBCBBB5DB6} = {F823671B-3ECA-4AE6-86DA-25E920D3FE64}
{834B4E85-64E5-4382-8465-548F332E5298} = {FBFEAD1F-29EB-4D99-A672-0CD8473E10B9}
{EFE0DC86-80FC-4D52-95B7-07654BA1A769} = {18BF8DD7-0585-48BF-8F97-AD333080CE06}
{8EA16BAB-465A-4C07-ABC4-1070D40067E9} = {F823671B-3ECA-4AE6-86DA-25E920D3FE64}
{19679B75-CE3A-4DF0-A3F0-CA369D2760A4} = {FBFEAD1F-29EB-4D99-A672-0CD8473E10B9}
{6B82F26D-5040-4453-B21B-C8D1F913CE4C} = {F823671B-3ECA-4AE6-86DA-25E920D3FE64}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
Expand Down
25 changes: 25 additions & 0 deletions dotnet/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,37 @@
<CSNoWarn>CS1998;CS1591</CSNoWarn>
<NoWarn>$(NoWarn);$(CSNoWarn);NU5104</NoWarn>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<IsPackable>false</IsPackable>
<EnableNetAnalyzers>true</EnableNetAnalyzers>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<IsTestProject>false</IsTestProject>
</PropertyGroup>

<PropertyGroup>
<RepoRoot>$(MSBuildThisFileDirectory)</RepoRoot>
</PropertyGroup>

<ItemGroup Condition="'$(IsTestProject)' == 'true'">
<PackageReference Include="ApprovalTests" Version="$(ApprovalTestVersion)" />
<PackageReference Include="FluentAssertions" Version="$(FluentAssertionVersion)" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(MicrosoftNETTestSdkVersion)" />
<PackageReference Include="xunit" Version="$(XUnitVersion)" />
<PackageReference Include="xunit.runner.console" Version="$(XUnitVersion)" />
<PackageReference Include="xunit.runner.visualstudio" Version="$(XUnitVersion)" />
</ItemGroup>

<ItemGroup Condition="'$(IsTestProject)' == 'true'">
<Content Include="$(RepoRoot)resource/**/*.*">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<Link>testData/%(RecursiveDir)%(Filename)%(Extension)</Link>
</Content>
</ItemGroup>

<ItemGroup Condition="'$(IncludeResourceFolder)' == 'true'">
<Content Include="$(RepoRoot)resource/**/*.*">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<Link>resource/%(RecursiveDir)%(Filename)%(Extension)</Link>
</Content>
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions dotnet/eng/Version.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<MicrosoftNETTestSdkVersion>17.7.0</MicrosoftNETTestSdkVersion>
<MicrosoftDotnetInteractive>1.0.0-beta.24229.4</MicrosoftDotnetInteractive>
<MicrosoftSourceLinkGitHubVersion>8.0.0</MicrosoftSourceLinkGitHubVersion>
<GoogleCloudAPIPlatformVersion>3.0.0</GoogleCloudAPIPlatformVersion>
<JsonSchemaVersion>4.3.0.2</JsonSchemaVersion>
</PropertyGroup>
</Project>
File renamed without changes
3 changes: 3 additions & 0 deletions dotnet/resource/images/square.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 6a57096

Please sign in to comment.