Skip to content

Commit

Permalink
Lots of QA, claude and ollama working with Chat Only
Browse files Browse the repository at this point in the history
  • Loading branch information
alnutile committed Aug 4, 2024
1 parent 7b88793 commit 12c9e31
Show file tree
Hide file tree
Showing 17 changed files with 143 additions and 329 deletions.
2 changes: 0 additions & 2 deletions Modules/LlmDriver/app/BaseClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ public function modifyPayload(array $payload, bool $noTools = false): array
$payload['tools'] = $this->getFunctions();
}

put_fixture('ollama_modified_payload.json', $payload);

return $payload;
}

Expand Down
1 change: 0 additions & 1 deletion Modules/LlmDriver/app/Functions/Chat.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class Chat extends FunctionContract
public bool $showInUi = false;

public array $toolTypes = [
ToolTypes::NoFunction,
];

protected string $name = 'chat_only';
Expand Down
1 change: 0 additions & 1 deletion Modules/LlmDriver/app/Functions/CreateDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class CreateDocument extends FunctionContract

public array $toolTypes = [
ToolTypes::Source,
ToolTypes::Chat,
];

protected string $name = 'create_document';
Expand Down
1 change: 0 additions & 1 deletion Modules/LlmDriver/app/Functions/GetWebSiteFromUrlTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class GetWebSiteFromUrlTool extends FunctionContract
ToolTypes::ChatCompletion,
ToolTypes::Source,
ToolTypes::Output,
ToolTypes::Chat,
];

protected string $name = 'get_web_site_from_url';
Expand Down
3 changes: 1 addition & 2 deletions Modules/LlmDriver/app/Functions/SearchTheWeb.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ class SearchTheWeb extends FunctionContract
ToolTypes::ChatCompletion,
ToolTypes::Source,
ToolTypes::Output,
ToolTypes::Chat,
];

protected string $name = 'search_the_web';

protected string $description = 'Search the web for a topic';
protected string $description = 'Search the web for a topic ONLY if the user asks for web search';

public function handle(
Message $message): FunctionResponse
Expand Down
13 changes: 4 additions & 9 deletions Modules/LlmDriver/app/OllamaClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public function chat(array $messages): CompletionResponse
throw new \Exception('Ollama API Error Chat');
}

put_fixture('ollama_chat_response.json', $response->json());
return OllamaChatCompletionResponse::from($response->json());
}

Expand All @@ -141,7 +142,7 @@ public function completionPool(array $prompts, int $temperature = 0): array
$model,
$baseUrl
) {
foreach ($prompts as $prompt) {
foreach ($prompts as $index => $prompt) {
$payload = [
'model' => $model,
'prompt' => $prompt,
Expand All @@ -150,10 +151,7 @@ public function completionPool(array $prompts, int $temperature = 0): array

$payload = $this->modifyPayload($payload, true);

Log::info('Ollama Request', [
'prompt' => $prompt,
'payload' => $payload,
]);
Log::info('Ollama Request index ' . $index);

$pool->withHeaders([
'content-type' => 'application/json',
Expand Down Expand Up @@ -198,8 +196,6 @@ public function completion(string $prompt): CompletionResponse
throw new \Exception('Ollama API Error Completion');
}

put_fixture('ollama_completion.json', $response->json());

return OllamaCompletionResponse::from($response->json());
}

Expand Down Expand Up @@ -262,8 +258,6 @@ public function getFunctions(): array

})->values()->toArray();

put_fixture('ollama_functions.json', $results);

return $results;
}

Expand All @@ -288,6 +282,7 @@ public function remapMessages(array $messages): array
->toArray();
})->toArray();


return $messages;
}
}
6 changes: 3 additions & 3 deletions app/Domains/Orchestration/OrchestrateVersionTwo.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ public function handle(

$messages = $chat->getChatResponse();

put_fixture('orchestrate_messages_first_send.json', $messages);

Log::info('[LaraChain] - Looking for Tools');

$response = LlmDriverFacade::driver($message->getDriver())
Expand Down Expand Up @@ -156,10 +154,12 @@ protected function chatWithTools(Chat $chat, Message $message, CompletionRespons

protected function justChat(Chat $chat, Message $message, ToolTypes $toolType): void
{
Log::info('[LaraChain] - Just Chatting');
Log::info('[LaraChain] - Just Chatting ' . $chat->getDriver());

$messages = $chat->getChatResponse();

put_fixture('orchestrate_messages_first_send.json', $messages);

$response = LlmDriverFacade::driver($chat->getDriver())
->setToolType($toolType)
->chat($messages);
Expand Down
59 changes: 49 additions & 10 deletions resources/js/Pages/Chat/Chatv2.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const toast = useToast();
import ChatMessageV2 from "@/Pages/Chat/ChatMessageV2.vue";
import DisplayMenu from "@/Components/DisplayMenu.vue";
import {Switch, SwitchGroup, SwitchLabel} from '@headlessui/vue'
const props = defineProps({
loading: {
type: Boolean,
Expand Down Expand Up @@ -41,6 +41,12 @@ const dateRangeChosen = ref({});
const referenceCollectionChosen = ref({});
const chatOnly = ref(false);
watch(chatOnly, () => {
form.tool = chatOnly.value ? 'chat' : '';
})
const dateRangeSelected = (dateRange) => {
dateRangeChosen.value = dateRange;
form.date_range = dateRange?.id
Expand Down Expand Up @@ -229,9 +235,42 @@ const rerun = (message) => {
<div class="w-full mx-auto px-4">
<label class="form-control join-item">
<div class="label" v-if="false">
<span class="label-text">Your bio</span>
<span class="label-text-alt">Alt label</span>
<div class="label">
<div class="border border-secondary rounded-md p-4">
<SwitchGroup>
<h2 class="text-lg font-medium leading-6 flex items-center justify-between gap-2 my-4 text-secondary">
<div class="flex items-center gap-2 justify-start">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-6">
<path stroke-linecap="round" stroke-linejoin="round" d="M20.25 8.511c.884.284 1.5 1.128 1.5 2.097v4.286c0 1.136-.847 2.1-1.98 2.193-.34.027-.68.052-1.02.072v3.091l-3-3c-1.354 0-2.694-.055-4.02-.163a2.115 2.115 0 0 1-.825-.242m9.345-8.334a2.126 2.126 0 0 0-.476-.095 48.64 48.64 0 0 0-8.048 0c-1.131.094-1.976 1.057-1.976 2.192v4.286c0 .837.46 1.58 1.155 1.951m9.345-8.334V6.637c0-1.621-1.152-3.026-2.76-3.235A48.455 48.455 0 0 0 11.25 3c-2.115 0-4.198.137-6.24.402-1.608.209-2.76 1.614-2.76 3.235v6.226c0 1.621 1.152 3.026 2.76 3.235.577.075 1.157.14 1.74.194V21l4.155-4.155" />
</svg>
<span>
Enable Chat Only
</span>
</div>
<Switch
as="button"
v-model="chatOnly"
:class="form.tool !== 'chat' ? 'bg-neutral' : 'bg-secondary'"
class="relative inline-flex h-6 w-11 items-center rounded-full"
>
<span class="sr-only">Enable notifications</span>
<span
:class="form.tool === 'chat' ? 'translate-x-6' : 'translate-x-1'"
class="inline-block h-4 w-4 transform rounded-full bg-white transition"
/>
</Switch>
</h2>
<SwitchLabel class="mr-4 prose">
<p>
The system defaults to chatting with your Collection. But sometimes
you might want to just chat with this thread and what is in your prompt.
Check this to work that way. You will still have some tools like "search_the_web
</p>
</SwitchLabel>
</SwitchGroup>
</div>
</div>
<div class="flex mt-5 ">
Expand Down Expand Up @@ -270,10 +309,6 @@ const rerun = (message) => {
</button>
</div>
</div>
<div class="label" v-if="false">
<span class="label-text-alt">Your bio</span>
<span class="label-text-alt">Alt label</span>
</div>
</label>
</div>
<div class="join-item px-4 mt-4">
Expand Down Expand Up @@ -323,6 +358,7 @@ const rerun = (message) => {
<div class="flex justify-start gap-2 items-center">
<Filters
v-if="form.tool !== 'chat'"
@filter="filter"
:collection="chat.collection"></Filters>
<StyleGuide
Expand All @@ -332,13 +368,15 @@ const rerun = (message) => {
</StyleGuide>
<DisplayMenu
v-if="form.tool !== 'chat'"
:items="usePage().props.date_ranges" @itemSelected="dateRangeSelected">
<template #title>
Date Range
</template>
</DisplayMenu>
<DisplayMenu
search="true"
v-if="form.tool !== 'chat'"
:search="true"
:items="usePage().props.reference_collections"
@itemSelected="referenceCollectionSelected">
<template #title>
Expand All @@ -355,7 +393,8 @@ const rerun = (message) => {
</DisplayMenu>
</div>
<div>
<div
v-if="form.tool !== 'chat'" v-auto-animate>
<h2
class="text-lg font-medium prose mt-4 px-2 mb-4 items-center justify-start flex gap-4"
>
Expand Down
31 changes: 3 additions & 28 deletions tests/fixtures/claude_messages_after_remap.json
Original file line number Diff line number Diff line change
@@ -1,39 +1,14 @@
[
{
"role": "user",
"content": "test1"
"content": "using the follow requirements list what are some solutions we have in this collection.\nWhen you find them just share a 1 liner to explain what they are about and another as to why you chose it\n\n---- requirements below ---\n# Request for Proposal: Website Enhancement and API Integration\n## 1. Introduction\nOur company, TechInnovate Solutions, is seeking proposals from qualified web development\nagencies or freelance developers to enhance our existing website and resolve critical issues\nwith our API and frontend components. This project aims to improve our website's\nfunctionality, performance, and user experience.\n## 2. Company Background\nTechInnovate Solutions is a leading provider of cloud-based software solutions for small to\nmedium-sized businesses. Founded in 2015, we have grown to serve over 10,000 customers\nacross North America. Our flagship product, CloudManage Pro, helps businesses streamline\ntheir operations, manage customer relationships, and optimize their supply chain processes.\n## 3. Project Overview\nWe are looking to address two main issues with our current website:\n1. API Integration Problem: Our website's backend, built with Laravel, is experiencing issues\nwith API calls, affecting data retrieval and submission processes.\n2. Frontend Banner Quality: The VueJS-powered banner on our homepage is displaying low-\nquality images, impacting the overall user experience and brand perception.\n## 4. Scope of Work\n### 4.1 API Issue Resolution\n- Diagnose the current API integration problems\n- Implement necessary fixes to ensure smooth data flow between frontend and backend\n- Optimize API calls for improved performance\n- Ensure proper error handling and logging\n- Update API documentation as needed\n### 4.2 VueJS Banner Enhancement\n- Investigate the cause of low-quality images in the banner\n- Implement image optimization techniques\n- Ensure responsive design across various devices and screen sizes\n- Improve loading times for banner images\n- Implement lazy loading if appropriate\n### 4.3 General Improvements\n- Conduct a brief audit of the existing codebase\n- Suggest and implement any critical optimizations\n- Ensure cross-browser compatibility\n- Improve overall website performance\n## 5. Technical Requirements\n### 5.1 Backend\n- Laravel framework (version 8.0 or higher)\n- PHP 7.4 or higher\n- MySQL database\n- RESTful API architecture\n### 5.2 Frontend\n- VueJS framework (version 3.0 or higher)\n- HTML5, CSS3, JavaScript\n- Responsive design principles\n- Modern browser compatibility (Chrome, Firefox, Safari, Edge)\n## 6. Deliverables\n1. Fully functional API with resolved integration issues\n2. Optimized VueJS banner with high-quality images\n3. Updated codebase with implemented improvements\n4. Comprehensive documentation of changes and optimizations\n5. Knowledge transfer session with our in-house development team\n## 7. Timeline\nWe anticipate this project to be completed within 2-3 weeks from the start date. Here's a\nproposed timeline:\n- Week 1: API diagnosis and initial fixes\n- Week 2: VueJS banner optimization and general improvements\n- Week 3: Final testing, documentation, and knowledge transfer\n## 8. Budget\nWhile we value quality work, we also have budget constraints. We are looking for the most\ncost-effective solution that meets our requirements. Please provide a detailed breakdown of\nyour costs in your proposal.\n## 9. Proposal Requirements\nYour proposal should include:\n1. Company\/Individual overview and relevant experience\n2. Detailed approach to solving our issues\n3. Proposed timeline\n4. Cost breakdown\n5. Team structure (if applicable)\n6. At least two references from similar projects\n## 10. Evaluation Criteria\nProposals will be evaluated based on the following criteria:\n1. Technical expertise (40%)\n2. Proposed approach and methodology (25%)\n3. Cost effectiveness (20%)\n4. Timeline and ability to meet deadlines (10%)\n5. References and past performance (5%)\n## 11. Submission Guidelines\nPlease submit your proposal in PDF format to [email protected] by [Insert Date].\nThe subject line should read \"Proposal - Website Enhancement Project\".\n## 12. Contact Information\nFor any questions or clarifications regarding this RFP, please contact:\nJohn Doe\nProject Manager, TechInnovate Solutions\nEmail: [email protected]\nPhone: (555) 123-4567\nWe look forward to reviewing your proposals and potentially working with you to enhance our\nwebsite and improve our user experience."
},
{
"role": "assistant",
"content": "test2"
"content": "Based on the requirements and the solutions presented in our conversation, here are some relevant solutions from our collection:\n\n1. Experienced Laravel developer:\n One-liner: Developer with extensive Laravel experience, including 10 years as a lead contractor at Pfizer.\n Why chosen: Directly addresses the technical expertise requirement for Laravel backend development.\n\n2. Full-stack development capability:\n One-liner: Comprehensive development skills covering both backend (API) and frontend (VueJS) issues.\n Why chosen: Aligns with the project's need for both API resolution and frontend banner enhancement.\n\n3. Build-measure-learn philosophy:\n One-liner: Iterative development approach focusing on continuous improvement and optimization.\n Why chosen: Fits the project's timeline and scope, allowing for ongoing refinement of both API and frontend components.\n\n4. Filament for Laravel:\n One-liner: Powerful admin panel and application framework for Laravel.\n Why chosen: Can address API integration issues and provide an easy-to-use interface for managing backend operations.\n\n5. Inertia and Vue for the frontend:\n One-liner: Approach combining Inertia and Vue for seamless frontend development.\n Why chosen: Aligns with the VueJS requirements and can help resolve frontend banner quality issues.\n\n6. Agile development approach:\n One-liner: Iterative development with frequent feedback and adjustments.\n Why chosen: Matches the need for flexibility and rapid development within the tight project timeline.\n\n7. Performance optimization techniques:\n One-liner: Methods to enhance website speed and responsiveness.\n Why chosen: Directly addresses the requirement for improving loading times and overall website performance."
},
{
"role": "user",
"content": "Using the surrounding context to continue this response thread"
},
{
"role": "assistant",
"content": [
{
"type": "text",
"text": "<thinking>test3<\/thinking>"
},
{
"type": "tool_use",
"id": "test_id",
"name": "test",
"input": []
}
]
},
{
"role": "user",
"content": [
{
"type": "tool_result",
"tool_use_id": "test_id",
"content": "test3"
}
]
"content": "can you tldr this thread for me"
}
]
Loading

0 comments on commit 12c9e31

Please sign in to comment.