Skip to content
Open
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
35 changes: 35 additions & 0 deletions sentiment-analysis-task/sentiment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
require('dotenv').config();
const { OpenAI } = require('openai');

const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
});

async function analyzeSentiment(text) {
try {
const completion = await openai.chat.completions.create({
model: "gpt-4",
messages: [
{
role: "system",
content: "You are a sentiment analysis assistant. Respond with only 'positive', 'negative', or 'neutral'.",
},
{
role: "user",
content: `What is the sentiment of this text: "${text}"?`,
},
],
});

const sentiment = completion.choices[0].message.content.trim();
console.log(`Sentiment: ${sentiment}`);
} catch (error) {
console.error("Error analyzing sentiment:", error);
}
}

// Example usage
const userText = "I love learning new things!";
analyzeSentiment(userText);


31 changes: 31 additions & 0 deletions task-02-claude/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
require('dotenv').config();
const axios = require('axios');

async function generateCodeWithClaude() {
const prompt = "Write a Python function to reverse a string.";

try {
const response = await axios.post(
'https://api.anthropic.com/v1/messages',
{
model: 'claude-2', // You may need to adjust based on available models
max_tokens: 300,
messages: [{ role: 'user', content: prompt }]
},
{
headers: {
'x-api-key': process.env.ANTHROPIC_API_KEY,
'content-type': 'application/json',
'anthropic-version': '2023-06-01'
}
}
);

const reply = response.data.content[0].text;
console.log("Claude's Response:\n", reply);
} catch (error) {
console.error("Error contacting Claude API:", error.response?.data || error.message);
}
}

generateCodeWithClaude();
Empty file.
29 changes: 29 additions & 0 deletions task-02-claude/03-embedding-models/generateEmbedding.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require('dotenv').config();
const axios = require('axios');

const inputText = "GitHub Models are powerful!";

async function getEmbeddingFromMistral() {
try {
const response = await axios.post(
'https://api.mistral.ai/v1/embeddings',
{
model: "mistral-embed", // Check for exact model name in API docs
input: inputText
},
{
headers: {
Authorization: `Bearer ${process.env.MISTRAL_API_KEY}`,
'Content-Type': 'application/json'
}
}
);

const embedding = response.data.data[0].embedding;
console.log("✅ Embedding Vector:\n", embedding);
} catch (error) {
console.error("❌ Error getting embedding:", error.response?.data || error.message);
}
}

getEmbeddingFromMistral();
Empty file added task-02-claude/generateCode.js
Empty file.