Skip to content

Commit

Permalink
Add config and fix typos
Browse files Browse the repository at this point in the history
  • Loading branch information
joshembling committed Dec 3, 2023
1 parent 72e9c46 commit 97d1ec2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
17 changes: 17 additions & 0 deletions config/laragenie.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,22 @@

// config for JoshEmbling/Laragenie
return [
'bot' => [
'name' => 'Laragenie',
'instructions' => 'Write only in markdown format. Only write factual data that can be pulled from indexed chunks.',
],

'openai' => [
'embedding' => [
'model' => 'text-embedding-ada-002',
'max_tokens' => 5,
],
'chat' => [
'model' => 'gpt-4-1106-preview',
],
],

'pinecone' => [
'topK' => 2,
],
];
14 changes: 7 additions & 7 deletions src/Commands/LaragenieCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function userQuestion(OpenAI\Client $openai, Pinecone $pinecone)

$question = $user_question;

$this->question("Asking BM Bot, '{$question}'...");
$this->question('Asking '.config('laragenie.bot.name').", '{$question}'...");

$getChunks = $this->askBot($openai, $pinecone, $question);
$response = $this->botResponse($openai, $getChunks, $question);
Expand All @@ -72,14 +72,14 @@ public function askBot(OpenAI\Client $openai, Pinecone $pinecone, string $questi
{
// Use OpenAI to generate context
$openai_res = $openai->embeddings()->create([
'model' => 'text-embedding-ada-002', // Use an appropriate model
'model' => config('laragenie.openai.embedding.model'),
'input' => $question,
'max_tokens' => 5, // Adjust as needed
'max_tokens' => config('laragenie.openai.embedding.max_tokens'),
]);

$pinecone_res = $pinecone->index(env('PINECONE_INDEX'))->vectors()->query(
vector: $openai_res->embeddings[0]->toArray()['embedding'],
topK: 2,
topK: config('laragenie.pinecone.topK'),
);

if (empty($pinecone_res->json()['matches'])) {
Expand All @@ -100,11 +100,11 @@ public function botResponse(OpenAI\Client $openai, $chunks, string $question)
try {
$response = spin(
fn () => $openai->chat()->create([
'model' => 'gpt-4-1106-preview',
'model' => config('laragenie.openai.chat.model'),
'messages' => [
[
'role' => 'system',
'content' => 'Write only in markdown format. Only write factual data that can be pulled from indexed chunks. If the user ever refers to "Brass Monkey", assume this is the name of the project. These are your relevant chunks: '.$chunks,
'content' => config('laragenie.bot.instruction').$chunks,
],
[
'role' => 'user',
Expand Down Expand Up @@ -164,7 +164,7 @@ public function indexFiles(array $chunks, string $file, OpenAI\Client $openai, P
{
foreach ($chunks as $idx => $chunk) {
$vector_response = $openai->embeddings()->create([
'model' => 'text-embedding-ada-002',
'model' => config('laragenie.openai.embedding.model'),
'input' => $chunk,
]);

Expand Down
2 changes: 1 addition & 1 deletion src/Helpers/Actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ trait Actions
public function welcome()
{
$this->newLine();
$this->warn('🐒 Hello! I\'m BM Bot, how may I assist you today?');
$this->warn('Hello, I am '.config('laragenie.bot.name').', how may I assist you today?');
$this->newLine();

sleep(1);
Expand Down

0 comments on commit 97d1ec2

Please sign in to comment.