Skip to content

Commit

Permalink
iterate
Browse files Browse the repository at this point in the history
  • Loading branch information
serefyarar committed Nov 22, 2024
1 parent 6d5f528 commit 6da8d63
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 21 deletions.
5 changes: 3 additions & 2 deletions api/src/controllers/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { S3Client, PutObjectCommand } from "@aws-sdk/client-s3";

const pinata = new PinataSDK({
pinataJwt: process.env.PINATA_JWT_KEY,
pinataGateway: "index-network.mypinata.cloud",
pinataGateway: "ipfs.index.network",
});

const s3Client = new S3Client({
Expand All @@ -29,7 +29,7 @@ export const uploadAvatar = async (req, res, next) => {
});

// Upload to IPFS via Pinata
const pinataResult = await pinata.upload.file(file);
const pinataResult = (await pinata.upload.file(file).group(`019335a5-ed91-770d-8f81-db7182c70c2e`));

// Upload to S3
const s3Params = {
Expand All @@ -44,6 +44,7 @@ export const uploadAvatar = async (req, res, next) => {
// Respond with both IPFS CID and S3 URL
res.json({
cid: pinataResult.cid,
pinata: `https://ipfs.index.network/files/${pinataResult.cid}`,
s3: `https://app-static.index.network/avatars/${pinataResult.cid}.jpg`,
});
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion api/src/controllers/lit-protocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export const getAction = async (req, res, next) => {
});

const litAction = await fetch(
`https://ipfs.index.network/ipfs/${cid}?pinataGatewayToken=${process.env.PINATA_IPFS_GATEWAY_KEY}`,
`https://ipfs.index.network/files/${cid}?pinataGatewayToken=${process.env.PINATA_IPFS_GATEWAY_KEY}`,
);
let litActionStr = await litAction.text();
litActionStr = `const ACTION_CALL_MODE="read"; ${litActionStr}`;
Expand Down
27 changes: 12 additions & 15 deletions api/src/language/completions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { searchItems } from "./search_item.js";
import { zodResponseFormat } from "openai/helpers/zod";
import { jsonSchemaToZod } from "json-schema-to-zod";

import { z } from "zod";

const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
});
Expand All @@ -16,9 +14,6 @@ const formatChatHistory = (messages) => {

export const handleCompletions = async ({ messages, indexIds, maxDocs=500, stream, schema, timeFilter }) => {

// TODO indexIds is optional because of chat summary.

// Fetch relevant documents
const docs = await searchItems({
indexIds,
query: formatChatHistory(messages),
Expand All @@ -32,13 +27,18 @@ export const handleCompletions = async ({ messages, indexIds, maxDocs=500, strea
const retrievedDocs = docs
.map(doc => {
if (doc.object === "cast") {
return `Cast details:
- text: ${doc.text}
- link: https://warpcast.com/${doc.author.username}/${doc.hash.substring(0, 12)}
- author: [${doc.author.name || doc.author.username}](https://warpcast.com/${doc.author.username})
- created_at: ${doc.timestamp}
----
`;
const authorName = doc.author.name || doc.author.username;
const castUrl = `https://warpcast.com/${doc.author.username}/${doc.hash.substring(0, 12)}`;
const authorUrl = `https://warpcast.com/${doc.author.username}`;

return [
'Cast details:',
`- text: ${doc.text}`,
`- link: ${castUrl}`,
`- author: [${authorName}](${authorUrl})`,
`- created_at: ${doc.timestamp}`,
'----'
].join('\n');
}
return JSON.stringify(doc);
})
Expand All @@ -53,17 +53,14 @@ export const handleCompletions = async ({ messages, indexIds, maxDocs=500, strea
});
}


const completionOptions = {
model: process.env.MODEL_CHAT,
messages,
temperature: 0,
stream: stream,
};

// Add response_format if schema is provided and streaming is disabled
if (schema && !stream) {
// Add validation to ensure schema has the expected structure
if (!schema.definitions?.response) {
throw new Error('Invalid schema format: missing definitions.response');
}
Expand Down
4 changes: 2 additions & 2 deletions api/src/services/did.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ export class DIDService {
if (ensProfile.image && ensProfile.image.startsWith(`ipfs://`)) {
ensProfile.image = ensProfile.image.replace(
`ipfs://`,
`https://ipfs.index.network/ipfs/`,
`https://ipfs.index.network/files/`,
);
}
return {
Expand All @@ -341,7 +341,7 @@ export class DIDService {
delete profileObj.controllerDID;

if (profileObj.avatar) {
profileObj.avatar = `https://ipfs.index.network/ipfs/${profileObj.avatar}`;
profileObj.avatar = `https://ipfs.index.network/files/${profileObj.avatar}`;
}

return profileObj;
Expand Down
2 changes: 1 addition & 1 deletion web-app/src/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const appConfig = {
ipfsProxy: "https://ipfs.index.network/ipfs/",
ipfsProxy: "https://ipfs.index.network/files/",
chains: {
ethereum: {
value: "ethereum",
Expand Down

0 comments on commit 6da8d63

Please sign in to comment.