Skip to content

[Vector] Introduce to VectorTools class - #23

Merged
rrr63 merged 1 commit into
doppar:1.xfrom
rrr63:vector
Nov 21, 2025
Merged

rrr63 merged 1 commit into
doppar:1.xfrom
rrr63:vector

Conversation

@rrr63

@rrr63 rrr63 commented Nov 21, 2025

Copy link
Copy Markdown
Member

Hello,

Here first version of Vector and Embedding tools.
Main goal here is to make 100% custom agent. Using vectors.

Here an example of a Doppar assistant agent, based on the official docs :

It only works with OpenAI yet, because we need a provider that can support vector embed

$agent = Agent::using(OpenAI::class) ->withKey("");

//I already saved all the docs in a .json locally using VectorTools::embedding on every markdown file
$docs = json_decode(file_get_contents(__DIR__ . '/vector_docs_cache.json'), true);

$question = "How to create a new OpenAI Doppar AI ?";
//we save the question as a vector with the new VectorTools class
$questionVector = VectorTools::embedding($agent,'text-embedding-3-small', $question);
//we get the full context by comparing question vectors with docs vectors
$context = VectorTools::getContext($docs, $questionVector);

//classic call with Doppar/Agent
$response = $agent->model('gpt-4o-mini')
            ->messages([
                ['role' => 'system', 'content' => 'You are a helpful Doppar assistant based on a context.'],
                ['role' => 'user', 'content' => "context:\n$context\nQuestion:$question"]
            ])
            ->send();

Here the LLM result :

To create a new OpenAI Agent in Doppar AI, you can follow the steps outlined below. This will set you up to interact with the OpenAI large language model using the Agent component.

Step 1: Install Doppar AI

Ensure you have Doppar AI installed in your PHP application:

composer require doppar/ai

Step 2: Register the AI Service Provider

Register the AI service provider in your config/app.php file:

'providers' => [
    // Other service providers...
    \Doppar\AI\AIServiceProvider::class,
],

Step 3: Set Up Your OpenAI API Key

Make sure to set your OpenAI API key in the environment file (.env):

OPENAI_API_KEY=your_openai_api_key

Step 4: Create the OpenAI Agent

You can create an OpenAI Agent instance in your application code. Here’s an example of how to do this:

use Doppar\AI\Agent;
use Doppar\AI\AgentFactory\Agent\OpenAI;

// Create the OpenAI agent and set up necessary parameters
$response = Agent::using(OpenAI::class)
    ->withKey(env('OPENAI_API_KEY')) // Provide your API key
    ->model('gpt-3.5-turbo') // Specify the model you want to use
    ->prompt('Explain quantum computing in simple terms') // Send a prompt
    ->send(); // Send the request and get the response

echo $response; // Output the response

Step 5: Customize Your Agent (Optional)

You can customize your agent by adjusting parameters such as temperature, max tokens, and adding system messages as needed. Here is an example of adding a system message and customizing parameters:

$response = Agent::using(OpenAI::class)
    ->withKey(env('OPENAI_API_KEY'))
    ->model('gpt-3.5-turbo')
    ->system('You are a knowledgeable AI assistant.')
    ->prompt('Explain quantum computing in simple terms')
    ->temperature(0.7) // Adjust creativity
    ->maxTokens(150) // Set the maximum response length
    ->send();

echo $response; // Output the response

Now you have a working OpenAI Agent set up within your Doppar AI application! You can adjust the prompts and parameters as needed to create various types of interactions with the OpenAI model.

@techmahedy

Copy link
Copy Markdown
Member

@rrr63, if everything is ok, update the docs nicely for #23
I know, you did a great job

@rrr63
rrr63 merged commit 6c566c7 into doppar:1.x Nov 21, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants