I craft beautiful and functional web experiences.
async waitForGPT(thread, assistant, instruction, interaction) {
try {
const run = await this.openai.beta.threads.runs.create(thread.id, {
assistant_id: assistant.id,
instructions: instruction,
});
let runStatus = await this.openai.beta.threads.runs.retrieve(thread.id, run.id);
// Polling mechanism to see if runStatus is completed
let isAvailable = true;
let attempts = 0;
while (runStatus.status !== 'completed' && attempts < 15) {
if (this.dF) {
this.dF.feedbackToDiscord(interaction, `runStatus: ${runStatus.status}...`);
}
runStatus = await this.openai.beta.threads.runs.retrieve(thread.id, run.id);
// Check for requires_action status (tool call required)
if (runStatus.status === 'requires_action') {
if (isAvailable) {
// Flow information
console.log('
Called on attempt:', attempts, '
', 'available:', isAvailable, '
');
isAvailable = false;
await this.useTool(runStatus, thread, run, interaction);
await this.getLatestMessage(thread.id);
isAvailable = true;
console.log(runStatus);
continue;
}
}
// Check for failed, cancelled, or expired status
if (['failed', 'cancelled', 'expired'].includes(runStatus.status)) {
console.log(
`Run status is '${runStatus.status}'. Unable to complete request.`,
);
break;
}
console.log('runStatus:', runStatus.status);
// Loop timer for 3 second
await new Promise((resolve) => setTimeout(resolve, 3000));
attempts++;
}
// Get the latest message
const latestMessage = await this.getLatestMessage(thread.id);
console.log('Latest message:', latestMessage?.content[0]?.text ?? 'No content found');
if (latestMessage?.content[0]?.text?.value !== undefined) {
if (this.dF) {
this.dF.feedbackToDiscord(interaction, 'Done!');
}
return latestMessage.content[0].text.value;
}
else {
if (this.dF) {
this.dF.feedbackToDiscord(interaction, 'An error occurred');
}
return 'An error occurred while processing your request.';
}
}
catch (error) {
console.error('Error in waitForGPT:', error);
if (this.dF) {
await interaction.followUp(
'An error occurred while processing your request.',
);
}
}
}
async login (req, res, next) {
try {
const user = await UserModel.authenticate(req.body.username, req.body.password);
const payload = {
username: user.username,
email: user.email,
userId: user._id
};
// Create the access token with the shorter lifespan.
const accessToken = jwt.sign(payload, Buffer.from(process.env.ACCESS_TOKEN_SECRET, 'base64'), {
algorithm: 'RS256',
expiresIn: process.env.ACCESS_TOKEN_LIFE
});
res
.status(201)
.json({
access_token: accessToken,
userId: payload.userId,
links: [
{
rel: 'profile',
href: `${req.protocol}://${req.get("host")}/api/v1/users/${user._id}`
}
]
});
} catch (error) {
// Authentication failed.
const err = createError(401, 'Credentials invalid or not provided.');
next(err);
}
}
Hello, my name is Fredrik Jurgell, and I am 27 years old. I recently graduated as a web programmer from Linnaeus University. I have extensive experience with technologies including:
Technical Skills:
Java, JavaScript, Next.js, CSS, .NET, Node.js, React, Express.js
Development Tools:
Database Development, GitLab/GitHub, Kubernetes
Notable Achievement: During my studies, I collaborated with a classmate to develop a bot project utilizing Chat-GPT to analyze news articles, for which we received the highest grade (A).
Internship Experience: During my internship at Srcful, I worked on integrating payment systems into the "Energy Warden" project, ensuring seamless and secure transaction processes. I enjoy working with modern technologies and am eager to contribute to solving complex technical challenges.
I highly value teamwork and thrive in collaborative environments where I can both share my knowledge and learn from others. I look forward to contributing to a team that delivers customized technical solutions and maximizes value for clients.
My Thesis Project in Collaboration with a Course Mate, where we received the highest grade (A).
View on GitHubView PDFHere you can view or download my full résumé, which includes details about my professional experience, education, and skills.
Download résumépublic void fit(float[][] X, int[] y) {
numFeatures = X[0].length;
int numSamples = X.length;
// Initialize data structures
for (int i = 0; i < numSamples; i++) {
int label = y[i];
classCounts.put(label, classCounts.getOrDefault(label, 0) + 1);
if (!featureSums.containsKey(label)) {
featureSums.put(label, new ArrayList<>(Collections.nCopies(numFeatures, 0.0f)));
featureSquaredSums.put(label, new ArrayList<>(Collections.nCopies(numFeatures, 0.0f)));
}
for (int j = 0; j < numFeatures; j++) {
float featureValue = X[i][j];
featureSums.get(label).set(j, featureSums.get(label).get(j) + featureValue);
featureSquaredSums.get(label).set(j, featureSquaredSums.get(label).get(j) + featureValue * featureValue);
}
}
for (Integer label : classCounts.keySet()) {
classProbabilities.put(label, (float) classCounts.get(label) / numSamples);
}
}
public async Task AddData(IEnumerable<Data> datas)
{
var index = "imdbdata";
var batchSize = 200;
var shipped = 0;
while (datas.Skip(shipped).Take(batchSize).Any())
{
var batch = datas.Skip(shipped).Take(batchSize);
var response = await elasticClient.BulkAsync(b => b.CreateMany(batch).Index(index));
shipped += batchSize;
}
}