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

refactor: from vendor to structural namespaces for models and platforms #68

Merged
merged 1 commit into from
Nov 23, 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
4 changes: 2 additions & 2 deletions examples/chat-claude-anthropic.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

use PhpLlm\LlmChain\Anthropic\Model\Claude;
use PhpLlm\LlmChain\Anthropic\Platform\Anthropic;
use PhpLlm\LlmChain\Chain;
use PhpLlm\LlmChain\Message\Message;
use PhpLlm\LlmChain\Message\MessageBag;
use PhpLlm\LlmChain\Model\Language\Claude;
use PhpLlm\LlmChain\Platform\Anthropic;
use Symfony\Component\Dotenv\Dotenv;
use Symfony\Component\HttpClient\HttpClient;

Expand Down
7 changes: 3 additions & 4 deletions examples/chat-gpt-azure.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
use PhpLlm\LlmChain\Chain;
use PhpLlm\LlmChain\Message\Message;
use PhpLlm\LlmChain\Message\MessageBag;
use PhpLlm\LlmChain\OpenAI\Model\Gpt;
use PhpLlm\LlmChain\OpenAI\Model\Gpt\Version;
use PhpLlm\LlmChain\OpenAI\Platform\Azure;
use PhpLlm\LlmChain\Model\Language\Gpt;
use PhpLlm\LlmChain\Platform\OpenAI\Azure;
use Symfony\Component\Dotenv\Dotenv;
use Symfony\Component\HttpClient\HttpClient;

Expand All @@ -24,7 +23,7 @@
$_ENV['AZURE_OPENAI_VERSION'],
$_ENV['AZURE_OPENAI_KEY'],
);
$llm = new Gpt($platform, Version::gpt4oMini());
$llm = new Gpt($platform, Gpt::GPT_4O_MINI);

$chain = new Chain($llm);
$messages = new MessageBag(
Expand Down
7 changes: 3 additions & 4 deletions examples/chat-gpt-openai.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
use PhpLlm\LlmChain\Chain;
use PhpLlm\LlmChain\Message\Message;
use PhpLlm\LlmChain\Message\MessageBag;
use PhpLlm\LlmChain\OpenAI\Model\Gpt;
use PhpLlm\LlmChain\OpenAI\Model\Gpt\Version;
use PhpLlm\LlmChain\OpenAI\Platform\OpenAI;
use PhpLlm\LlmChain\Model\Language\Gpt;
use PhpLlm\LlmChain\Platform\OpenAI\OpenAI;
use Symfony\Component\Dotenv\Dotenv;
use Symfony\Component\HttpClient\HttpClient;

Expand All @@ -18,7 +17,7 @@
}

$platform = new OpenAI(HttpClient::create(), $_ENV['OPENAI_API_KEY']);
$llm = new Gpt($platform, Version::gpt4oMini(), [
$llm = new Gpt($platform, Gpt::GPT_4O_MINI, [
'temperature' => 0.5, // default options for the model
]);

Expand Down
7 changes: 3 additions & 4 deletions examples/chat-o1-openai.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
use PhpLlm\LlmChain\Chain;
use PhpLlm\LlmChain\Message\Message;
use PhpLlm\LlmChain\Message\MessageBag;
use PhpLlm\LlmChain\OpenAI\Model\Gpt;
use PhpLlm\LlmChain\OpenAI\Model\Gpt\Version;
use PhpLlm\LlmChain\OpenAI\Platform\OpenAI;
use PhpLlm\LlmChain\Model\Language\Gpt;
use PhpLlm\LlmChain\Platform\OpenAI\OpenAI;
use Symfony\Component\Dotenv\Dotenv;
use Symfony\Component\HttpClient\HttpClient;

Expand All @@ -23,7 +22,7 @@
}

$platform = new OpenAI(HttpClient::create(), $_ENV['OPENAI_API_KEY']);
$llm = new Gpt($platform, Version::o1Preview());
$llm = new Gpt($platform, Gpt::O1_PREVIEW);

$prompt = <<<PROMPT
I want to build a Symfony app in PHP 8.2 that takes user questions and looks them
Expand Down
9 changes: 4 additions & 5 deletions examples/embeddings-openai.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<?php

use PhpLlm\LlmChain\OpenAI\Model\Embeddings;
use PhpLlm\LlmChain\OpenAI\Model\Embeddings\Version;
use PhpLlm\LlmChain\OpenAI\Platform\OpenAI;
use PhpLlm\LlmChain\Model\Embeddings\OpenAI as Embeddings;
use PhpLlm\LlmChain\Platform\OpenAI\OpenAI as Platform;
use Symfony\Component\Dotenv\Dotenv;
use Symfony\Component\HttpClient\HttpClient;

Expand All @@ -14,8 +13,8 @@
exit(1);
}

$platform = new OpenAI(HttpClient::create(), $_ENV['OPENAI_API_KEY']);
$embeddings = new Embeddings($platform, Version::textEmbedding3Small());
$platform = new Platform(HttpClient::create(), $_ENV['OPENAI_API_KEY']);
$embeddings = new Embeddings($platform);

$vector = $embeddings->create(<<<TEXT
Once upon a time, there was a country called Japan. It was a beautiful country with a lot of mountains and rivers.
Expand Down
6 changes: 3 additions & 3 deletions examples/embeddings-voyage.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

use PhpLlm\LlmChain\Voyage\Model\Voyage;
use PhpLlm\LlmChain\Voyage\Platform\Voyage as VoyagePlatform;
use PhpLlm\LlmChain\Model\Embeddings\Voyage;
use PhpLlm\LlmChain\Platform\Voyage as Platform;
use Symfony\Component\Dotenv\Dotenv;
use Symfony\Component\HttpClient\HttpClient;

Expand All @@ -13,7 +13,7 @@
exit(1);
}

$platform = new VoyagePlatform(HttpClient::create(), $_ENV['VOYAGE_API_KEY']);
$platform = new Platform(HttpClient::create(), $_ENV['VOYAGE_API_KEY']);
$embeddings = new Voyage($platform);

$vector = $embeddings->create(<<<TEXT
Expand Down
7 changes: 3 additions & 4 deletions examples/image-describer-binary.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
use PhpLlm\LlmChain\Message\Content\Image;
use PhpLlm\LlmChain\Message\Message;
use PhpLlm\LlmChain\Message\MessageBag;
use PhpLlm\LlmChain\OpenAI\Model\Gpt;
use PhpLlm\LlmChain\OpenAI\Model\Gpt\Version;
use PhpLlm\LlmChain\OpenAI\Platform\OpenAI;
use PhpLlm\LlmChain\Model\Language\Gpt;
use PhpLlm\LlmChain\Platform\OpenAI\OpenAI;
use Symfony\Component\Dotenv\Dotenv;
use Symfony\Component\HttpClient\HttpClient;

Expand All @@ -19,7 +18,7 @@
}

$platform = new OpenAI(HttpClient::create(), $_ENV['OPENAI_API_KEY']);
$llm = new Gpt($platform, Version::gpt4oMini());
$llm = new Gpt($platform, Gpt::GPT_4O_MINI);

$chain = new Chain($llm);
$messages = new MessageBag(
Expand Down
7 changes: 3 additions & 4 deletions examples/image-describer-url.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
use PhpLlm\LlmChain\Message\Content\Image;
use PhpLlm\LlmChain\Message\Message;
use PhpLlm\LlmChain\Message\MessageBag;
use PhpLlm\LlmChain\OpenAI\Model\Gpt;
use PhpLlm\LlmChain\OpenAI\Model\Gpt\Version;
use PhpLlm\LlmChain\OpenAI\Platform\OpenAI;
use PhpLlm\LlmChain\Model\Language\Gpt;
use PhpLlm\LlmChain\Platform\OpenAI\OpenAI;
use Symfony\Component\Dotenv\Dotenv;
use Symfony\Component\HttpClient\HttpClient;

Expand All @@ -19,7 +18,7 @@
}

$platform = new OpenAI(HttpClient::create(), $_ENV['OPENAI_API_KEY']);
$llm = new Gpt($platform, Version::gpt4oMini());
$llm = new Gpt($platform, Gpt::GPT_4O_MINI);

$chain = new Chain($llm);
$messages = new MessageBag(
Expand Down
11 changes: 5 additions & 6 deletions examples/store-mongodb-similarity-search.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
use PhpLlm\LlmChain\DocumentEmbedder;
use PhpLlm\LlmChain\Message\Message;
use PhpLlm\LlmChain\Message\MessageBag;
use PhpLlm\LlmChain\OpenAI\Model\Embeddings;
use PhpLlm\LlmChain\OpenAI\Model\Gpt;
use PhpLlm\LlmChain\OpenAI\Model\Gpt\Version;
use PhpLlm\LlmChain\OpenAI\Platform\OpenAI;
use PhpLlm\LlmChain\Model\Embeddings\OpenAI as Embeddings;
use PhpLlm\LlmChain\Model\Language\Gpt;
use PhpLlm\LlmChain\Platform\OpenAI\OpenAI as Platform;
use PhpLlm\LlmChain\Store\MongoDB\Store;
use PhpLlm\LlmChain\ToolBox\ChainProcessor;
use PhpLlm\LlmChain\ToolBox\Tool\SimilaritySearch;
Expand Down Expand Up @@ -54,14 +53,14 @@
}

// create embeddings for documents
$platform = new OpenAI(HttpClient::create(), $_ENV['OPENAI_API_KEY']);
$platform = new Platform(HttpClient::create(), $_ENV['OPENAI_API_KEY']);
$embedder = new DocumentEmbedder($embeddings = new Embeddings($platform), $store);
$embedder->embed($documents);

// initialize the index
$store->initialize();

$llm = new Gpt($platform, Version::gpt4oMini());
$llm = new Gpt($platform, Gpt::GPT_4O_MINI);

$similaritySearch = new SimilaritySearch($embeddings, $store);
$toolBox = new ToolBox(new ToolAnalyzer(), [$similaritySearch]);
Expand Down
11 changes: 5 additions & 6 deletions examples/store-pinecone-similarity-search.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
use PhpLlm\LlmChain\DocumentEmbedder;
use PhpLlm\LlmChain\Message\Message;
use PhpLlm\LlmChain\Message\MessageBag;
use PhpLlm\LlmChain\OpenAI\Model\Embeddings;
use PhpLlm\LlmChain\OpenAI\Model\Gpt;
use PhpLlm\LlmChain\OpenAI\Model\Gpt\Version;
use PhpLlm\LlmChain\OpenAI\Platform\OpenAI;
use PhpLlm\LlmChain\Model\Embeddings\OpenAI as Embeddings;
use PhpLlm\LlmChain\Model\Language\Gpt;
use PhpLlm\LlmChain\Platform\OpenAI\OpenAI as Platform;
use PhpLlm\LlmChain\Store\Pinecone\Store;
use PhpLlm\LlmChain\ToolBox\ChainProcessor;
use PhpLlm\LlmChain\ToolBox\Tool\SimilaritySearch;
Expand Down Expand Up @@ -48,11 +47,11 @@
}

// create embeddings for documents
$platform = new OpenAI(HttpClient::create(), $_ENV['OPENAI_API_KEY']);
$platform = new Platform(HttpClient::create(), $_ENV['OPENAI_API_KEY']);
$embedder = new DocumentEmbedder($embeddings = new Embeddings($platform), $store);
$embedder->embed($documents);

$llm = new Gpt($platform, Version::gpt4oMini());
$llm = new Gpt($platform, Gpt::GPT_4O_MINI);

$similaritySearch = new SimilaritySearch($embeddings, $store);
$toolBox = new ToolBox(new ToolAnalyzer(), [$similaritySearch]);
Expand Down
4 changes: 2 additions & 2 deletions examples/stream-claude-anthropic.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

use PhpLlm\LlmChain\Anthropic\Model\Claude;
use PhpLlm\LlmChain\Anthropic\Platform\Anthropic;
use PhpLlm\LlmChain\Chain;
use PhpLlm\LlmChain\Message\Message;
use PhpLlm\LlmChain\Message\MessageBag;
use PhpLlm\LlmChain\Model\Language\Claude;
use PhpLlm\LlmChain\Platform\Anthropic;
use Symfony\Component\Dotenv\Dotenv;
use Symfony\Component\HttpClient\HttpClient;

Expand Down
7 changes: 3 additions & 4 deletions examples/stream-gpt-openai.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
use PhpLlm\LlmChain\Chain;
use PhpLlm\LlmChain\Message\Message;
use PhpLlm\LlmChain\Message\MessageBag;
use PhpLlm\LlmChain\OpenAI\Model\Gpt;
use PhpLlm\LlmChain\OpenAI\Model\Gpt\Version;
use PhpLlm\LlmChain\OpenAI\Platform\OpenAI;
use PhpLlm\LlmChain\Model\Language\Gpt;
use PhpLlm\LlmChain\Platform\OpenAI\OpenAI;
use Symfony\Component\Dotenv\Dotenv;
use Symfony\Component\HttpClient\EventSourceHttpClient;

Expand All @@ -18,7 +17,7 @@
}

$platform = new OpenAI(new EventSourceHttpClient(), $_ENV['OPENAI_API_KEY']);
$llm = new Gpt($platform, Version::gpt4oMini());
$llm = new Gpt($platform, Gpt::GPT_4O_MINI);

$chain = new Chain($llm);
$messages = new MessageBag(
Expand Down
7 changes: 3 additions & 4 deletions examples/structured-output-clock.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
use PhpLlm\LlmChain\Chain;
use PhpLlm\LlmChain\Message\Message;
use PhpLlm\LlmChain\Message\MessageBag;
use PhpLlm\LlmChain\OpenAI\Model\Gpt;
use PhpLlm\LlmChain\OpenAI\Model\Gpt\Version;
use PhpLlm\LlmChain\OpenAI\Platform\OpenAI;
use PhpLlm\LlmChain\Model\Language\Gpt;
use PhpLlm\LlmChain\Platform\OpenAI\OpenAI;
use PhpLlm\LlmChain\StructuredOutput\ChainProcessor as StructuredOutputProcessor;
use PhpLlm\LlmChain\StructuredOutput\ResponseFormatFactory;
use PhpLlm\LlmChain\ToolBox\ChainProcessor as ToolProcessor;
Expand All @@ -28,7 +27,7 @@
}

$platform = new OpenAI(HttpClient::create(), $_ENV['OPENAI_API_KEY']);
$llm = new Gpt($platform, Version::gpt4oMini());
$llm = new Gpt($platform, Gpt::GPT_4O_MINI);

$clock = new Clock(new SymfonyClock());
$toolBox = new ToolBox(new ToolAnalyzer(), [$clock]);
Expand Down
7 changes: 3 additions & 4 deletions examples/structured-output-math.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
use PhpLlm\LlmChain\Chain;
use PhpLlm\LlmChain\Message\Message;
use PhpLlm\LlmChain\Message\MessageBag;
use PhpLlm\LlmChain\OpenAI\Model\Gpt;
use PhpLlm\LlmChain\OpenAI\Model\Gpt\Version;
use PhpLlm\LlmChain\OpenAI\Platform\OpenAI;
use PhpLlm\LlmChain\Model\Language\Gpt;
use PhpLlm\LlmChain\Platform\OpenAI\OpenAI;
use PhpLlm\LlmChain\StructuredOutput\ChainProcessor;
use PhpLlm\LlmChain\StructuredOutput\ResponseFormatFactory;
use PhpLlm\LlmChain\Tests\Fixture\StructuredOutput\MathReasoning;
Expand All @@ -24,7 +23,7 @@
}

$platform = new OpenAI(HttpClient::create(), $_ENV['OPENAI_API_KEY']);
$llm = new Gpt($platform, Version::gpt4oMini());
$llm = new Gpt($platform, Gpt::GPT_4O_MINI);
$serializer = new Serializer([new ObjectNormalizer()], [new JsonEncoder()]);

$processor = new ChainProcessor(new ResponseFormatFactory(), $serializer);
Expand Down
7 changes: 3 additions & 4 deletions examples/toolbox-clock.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
use PhpLlm\LlmChain\Chain;
use PhpLlm\LlmChain\Message\Message;
use PhpLlm\LlmChain\Message\MessageBag;
use PhpLlm\LlmChain\OpenAI\Model\Gpt;
use PhpLlm\LlmChain\OpenAI\Model\Gpt\Version;
use PhpLlm\LlmChain\OpenAI\Platform\OpenAI;
use PhpLlm\LlmChain\Model\Language\Gpt;
use PhpLlm\LlmChain\Platform\OpenAI\OpenAI;
use PhpLlm\LlmChain\ToolBox\ChainProcessor;
use PhpLlm\LlmChain\ToolBox\Tool\Clock;
use PhpLlm\LlmChain\ToolBox\ToolAnalyzer;
Expand All @@ -23,7 +22,7 @@
}

$platform = new OpenAI(HttpClient::create(), $_ENV['OPENAI_API_KEY']);
$llm = new Gpt($platform, Version::gpt4oMini());
$llm = new Gpt($platform, Gpt::GPT_4O_MINI);

$clock = new Clock(new SymfonyClock());
$toolBox = new ToolBox(new ToolAnalyzer(), [$clock]);
Expand Down
7 changes: 3 additions & 4 deletions examples/toolbox-serpapi.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
use PhpLlm\LlmChain\Chain;
use PhpLlm\LlmChain\Message\Message;
use PhpLlm\LlmChain\Message\MessageBag;
use PhpLlm\LlmChain\OpenAI\Model\Gpt;
use PhpLlm\LlmChain\OpenAI\Model\Gpt\Version;
use PhpLlm\LlmChain\OpenAI\Platform\OpenAI;
use PhpLlm\LlmChain\Model\Language\Gpt;
use PhpLlm\LlmChain\Platform\OpenAI\OpenAI;
use PhpLlm\LlmChain\ToolBox\ChainProcessor;
use PhpLlm\LlmChain\ToolBox\Tool\SerpApi;
use PhpLlm\LlmChain\ToolBox\ToolAnalyzer;
Expand All @@ -22,7 +21,7 @@
}
$httpClient = HttpClient::create();
$platform = new OpenAI($httpClient, $_ENV['OPENAI_API_KEY']);
$llm = new Gpt($platform, Version::gpt4oMini());
$llm = new Gpt($platform, Gpt::GPT_4O_MINI);

$serpApi = new SerpApi($httpClient, $_ENV['SERP_API_KEY']);
$toolBox = new ToolBox(new ToolAnalyzer(), [$serpApi]);
Expand Down
7 changes: 3 additions & 4 deletions examples/toolbox-weather.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
use PhpLlm\LlmChain\Chain;
use PhpLlm\LlmChain\Message\Message;
use PhpLlm\LlmChain\Message\MessageBag;
use PhpLlm\LlmChain\OpenAI\Model\Gpt;
use PhpLlm\LlmChain\OpenAI\Model\Gpt\Version;
use PhpLlm\LlmChain\OpenAI\Platform\OpenAI;
use PhpLlm\LlmChain\Model\Language\Gpt;
use PhpLlm\LlmChain\Platform\OpenAI\OpenAI;
use PhpLlm\LlmChain\ToolBox\ChainProcessor;
use PhpLlm\LlmChain\ToolBox\Tool\OpenMeteo;
use PhpLlm\LlmChain\ToolBox\ToolAnalyzer;
Expand All @@ -23,7 +22,7 @@

$httpClient = HttpClient::create();
$platform = new OpenAI($httpClient, $_ENV['OPENAI_API_KEY']);
$llm = new Gpt($platform, Version::gpt4oMini());
$llm = new Gpt($platform, Gpt::GPT_4O_MINI);

$wikipedia = new OpenMeteo($httpClient);
$toolBox = new ToolBox(new ToolAnalyzer(), [$wikipedia]);
Expand Down
7 changes: 3 additions & 4 deletions examples/toolbox-wikipedia.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
use PhpLlm\LlmChain\Chain;
use PhpLlm\LlmChain\Message\Message;
use PhpLlm\LlmChain\Message\MessageBag;
use PhpLlm\LlmChain\OpenAI\Model\Gpt;
use PhpLlm\LlmChain\OpenAI\Model\Gpt\Version;
use PhpLlm\LlmChain\OpenAI\Platform\OpenAI;
use PhpLlm\LlmChain\Model\Language\Gpt;
use PhpLlm\LlmChain\Platform\OpenAI\OpenAI;
use PhpLlm\LlmChain\ToolBox\ChainProcessor;
use PhpLlm\LlmChain\ToolBox\Tool\Wikipedia;
use PhpLlm\LlmChain\ToolBox\ToolAnalyzer;
Expand All @@ -23,7 +22,7 @@

$httpClient = HttpClient::create();
$platform = new OpenAI($httpClient, $_ENV['OPENAI_API_KEY']);
$llm = new Gpt($platform, Version::gpt4oMini());
$llm = new Gpt($platform, Gpt::GPT_4O_MINI);

$wikipedia = new Wikipedia($httpClient);
$toolBox = new ToolBox(new ToolAnalyzer(), [$wikipedia]);
Expand Down
7 changes: 3 additions & 4 deletions examples/toolbox-youtube.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
use PhpLlm\LlmChain\Chain;
use PhpLlm\LlmChain\Message\Message;
use PhpLlm\LlmChain\Message\MessageBag;
use PhpLlm\LlmChain\OpenAI\Model\Gpt;
use PhpLlm\LlmChain\OpenAI\Model\Gpt\Version;
use PhpLlm\LlmChain\OpenAI\Platform\OpenAI;
use PhpLlm\LlmChain\Model\Language\Gpt;
use PhpLlm\LlmChain\Platform\OpenAI\OpenAI;
use PhpLlm\LlmChain\ToolBox\ChainProcessor;
use PhpLlm\LlmChain\ToolBox\Tool\YouTubeTranscriber;
use PhpLlm\LlmChain\ToolBox\ToolAnalyzer;
Expand All @@ -23,7 +22,7 @@

$httpClient = HttpClient::create();
$platform = new OpenAI($httpClient, $_ENV['OPENAI_API_KEY']);
$llm = new Gpt($platform, Version::gpt4oMini());
$llm = new Gpt($platform, Gpt::GPT_4O_MINI);

$transcriber = new YouTubeTranscriber($httpClient);
$toolBox = new ToolBox(new ToolAnalyzer(), [$transcriber]);
Expand Down
Loading