-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
adnan wahab
committed
Oct 21, 2024
1 parent
1416483
commit b0085bf
Showing
9 changed files
with
315 additions
and
388 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/bin/bash | ||
|
||
# List of package paths | ||
packages=( | ||
"packages/llm/ollama" | ||
"packages/llm/llama_cpp" | ||
"packages/llm/llama-factory" | ||
"packages/llm/exllama" | ||
"packages/vlm/llama-vision" | ||
) | ||
|
||
# Store the initial directory | ||
initial_dir=$(pwd) | ||
|
||
# Build each container | ||
for package in "${packages[@]}"; do | ||
echo "-----------------------------------------" | ||
echo "Building container for $package" | ||
|
||
# Check if the directory exists | ||
if [ ! -d "$package" ]; then | ||
echo "Error: Directory $package does not exist. Skipping..." | ||
continue | ||
fi | ||
|
||
# Change to the package directory | ||
cd "$initial_dir/$package" || { echo "Error: Unable to change to directory $package. Skipping..."; continue; } | ||
|
||
# Check if a build script exists | ||
if [ -f "build.sh" ]; then | ||
echo "Found build.sh, executing..." | ||
chmod +x build.sh | ||
./build.sh | ||
elif [ -f "Dockerfile" ]; then | ||
# Build the Docker image | ||
image_name="${package##*/}" | ||
echo "No build.sh found. Building Docker image: $image_name" | ||
docker build -t "$image_name" . | ||
else | ||
echo "No build script or Dockerfile found in $package. Skipping..." | ||
fi | ||
|
||
# Return to the initial directory | ||
cd "$initial_dir" || { echo "Error: Unable to return to initial directory. Exiting..."; exit 1; } | ||
done | ||
|
||
echo "-----------------------------------------" | ||
echo "Container build process completed." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import fs from "fs"; | ||
|
||
async function runOllamaCommand(prompt) { | ||
try { | ||
const command = `ollama run llama2 "${prompt}"`; | ||
|
||
const result = await Bun.spawn(["sh", "-c", command]).text(); | ||
|
||
const logEntry = { | ||
timestamp: new Date().toISOString(), | ||
prompt: prompt, | ||
result: result | ||
}; | ||
|
||
const logDir = "/derp/log"; | ||
const logFile = path.join(logDir, "llama.json"); | ||
|
||
if (!fs.existsSync(logDir)) { | ||
fs.mkdirSync(logDir, { recursive: true }); | ||
} | ||
|
||
let logData = []; | ||
if (fs.existsSync(logFile)) { | ||
const existingLog = fs.readFileSync(logFile, "utf-8"); | ||
logData = JSON.parse(existingLog); | ||
} | ||
|
||
logData.push(logEntry); | ||
fs.writeFileSync(logFile, JSON.stringify(logData, null, 2)); | ||
return result.trim(); | ||
} catch (error) { | ||
console.error("Error running Ollama command:", error); | ||
throw error; | ||
} | ||
} | ||
|
||
export async function handleOllamaRequest(req) { | ||
if (req.method !== 'POST') { | ||
return new Response('Method not allowed', { status: 405 }); | ||
} | ||
|
||
try { | ||
const { prompt } = await req.json(); | ||
|
||
if (!prompt) { | ||
return new Response(JSON.stringify({ error: 'Prompt is required' }), { | ||
status: 400, | ||
headers: { 'Content-Type': 'application/json' } | ||
}); | ||
} | ||
|
||
const result = await runOllamaCommand(prompt); | ||
|
||
return new Response(JSON.stringify({ result }), { | ||
status: 200, | ||
headers: { 'Content-Type': 'application/json' } | ||
}); | ||
} catch (error) { | ||
console.error('Error in handleOllamaRequest:', error); | ||
return new Response(JSON.stringify({ error: 'Internal server error' }), { | ||
status: 500, | ||
headers: { 'Content-Type': 'application/json' } | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.