Skip to content

Commit

Permalink
Merge pull request #110 from indexnetwork/sources
Browse files Browse the repository at this point in the history
cleanup
  • Loading branch information
confxsd authored May 17, 2024
2 parents 5aa375e + 1b4a999 commit 0308637
Show file tree
Hide file tree
Showing 16 changed files with 78 additions and 4,018 deletions.
8 changes: 3 additions & 5 deletions sdk/js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ const wallet = new Wallet(process.env.PRIVATE_KEY);

const indexClient = new IndexClient({
wallet,
domain: "index.network",
network: "ethereum", // provide your network
network: "dev", // or mainnet
});
```

Expand All @@ -64,8 +63,7 @@ const indexId = await indexClient.createIndex({
Voilà, now you have a truly decentralized index to interact with! Though it's empty, which means we need to create and add an [`Item`](../api-reference/indexing/item.md) into it so we can interact. Let's do that.

```typescript
const webPageId = await indexClient.createWebPage({
title: "Post medium publishing",
const webPageId = await indexClient.crawlWebPage({
url: "http://www.paulgraham.com/publishing.html",
});

Expand All @@ -83,7 +81,7 @@ const queryResponse = await indexClient.chat({
role: "user",
},
],
indexes: [indexId], // You can add all the indexes of a user as well
sources: [indexId], // You can add all the indexes of a user as well
});

console.log(queryResponse);
Expand Down
2 changes: 1 addition & 1 deletion sdk/js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@indexnetwork/sdk",
"version": "0.0.14",
"version": "0.0.15",
"type": "module",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
9 changes: 3 additions & 6 deletions sdk/js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,11 @@ export default class IndexClient {

public async *chat({
id,
indexes,
did,
sources,
messages,
}: {
id: string;
indexes: string[];
did?: string;
sources: string[];
messages: Message[];
}): AsyncGenerator<string, void, undefined> {
const response = await fetch(`${this.baseUrl}/discovery/chat`, {
Expand All @@ -168,8 +166,7 @@ export default class IndexClient {
body: JSON.stringify({
messages,
id,
indexIds: indexes,
did,
sources,
}),
});

Expand Down
2 changes: 1 addition & 1 deletion sdk/python/README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ messages = [
},
]

response = client.chat(chat_id, messages, index_id)
response = client.chat(chat_id, messages, sources=[index_id])

print(response)
```
Expand Down
21 changes: 21 additions & 0 deletions sdk/python/indexclient/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,27 @@ def create_index(self, title, signer_function=None):

return self._request("/indexes", "POST", body)

def chat(self, id, sources, messages):
url = f"{self.base_url}/discovery/chat"
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {self.session}",
}
body = {
'messages': messages,
'id': id,
'sources': sources
}
response = requests.post(url, headers=headers, data=json.dumps(body), stream=True)

if response.status_code != 200:
raise Exception('Error streaming messages')

for line in response.iter_lines():
if line:
decoded_line = line.decode('utf-8')
yield decoded_line

def add_item_to_index(self, index_id, item_id):
return self._request(f"/indexes/{index_id}/items/{item_id}", "POST")

Expand Down
2 changes: 1 addition & 1 deletion sdk/python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

setup(
name='indexnetwork-sdk',
version='0.0.14',
version='0.0.15',
description='Index Network SDK',
long_description=open(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'README.MD')).read(),
long_description_content_type='text/markdown',
Expand Down
3,881 changes: 0 additions & 3,881 deletions widget-demo/dist/bundle.js

This file was deleted.

11 changes: 0 additions & 11 deletions widget-demo/dist/index.html

This file was deleted.

2 changes: 1 addition & 1 deletion widget-demo/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ function App() {
<div>
<IndexChat
sources={[
"kjzl6kcym7w8y6rf31ljq3867je1l4vhw426g9e13dk2m3516z7yccz3x47t3l4",
"did:pkh:eip155:1:0x4b30778B5c23751896749d5e25196D5F4F1fb4a1",
]}
style={{
darkMode: false,
Expand Down
71 changes: 4 additions & 67 deletions widget/src/components/ChatBody.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,21 @@
// import { useApi } from "@/context/APIContext";
// import { useApp } from "@/context/AppContext";
// import { useAuth } from "@/context/AuthContext";
// import { useRouteParams } from "@/hooks/useRouteParams";
import { useChat, type Message } from "ai/react";
import { ButtonScrollToBottom } from "@/components/ai/button-scroll-to-bottom";
import { ChatList } from "@/components/ai/chat-list";
import { ChatPanel } from "@/components/ai/chat-panel";
import { ChatScrollAnchor } from "@/components/ai/chat-scroll-anchor";
import { EmptyScreen } from "@/components/ai/empty-screen";
import AskInput from "@/components/AskInput";
import {
ComponentProps,
FC,
useCallback,
useEffect,
useMemo,
useRef,
useState,
} from "react";
import { toast } from "react-hot-toast";
import { maskDID } from "@/utils";
import BodyPlaceholder from "./BodyPlaceholder";
import Icon from "@/assets/icon";
import { useTheme } from "@/contexts/ThemeContext";
import { appConfig } from "@/config";
import { useIndexChat } from "@/contexts/ChatContext";
// import NoIndexes from "../NoIndexes";

export interface ChatProps extends ComponentProps<"div"> {
initialMessages?: Message[];
Expand All @@ -37,11 +27,6 @@ export interface MessageWithIndex extends Message {
}

const ChatBody = () => {
// const { viewedProfile, leftSectionIndexes, leftTabKey } = useApp();

// const { session } = useAuth();
// const { viewedIndex } = useApp();
// const { isIndex, id } = useRouteParams();
const { defaultQuestions, sources, chatID } = useIndexChat();
const { darkMode } = useTheme();

Expand Down Expand Up @@ -101,32 +86,8 @@ const ChatBody = () => {
}
};

// const tipBoxes = [
// {
// content:
// "What are the best practices for scaling a ComposeDB application?",
// icon: <Icon.LightBulb />,
// },
// {
// content: "How can I integrate Ceramic Network with Lit Protocol?",
// icon: <Icon.LightBulb />,
// },
// ];

const apiUrl = `${appConfig.apiUrl}/api/discovery/chat`;
const initialMessages: Message[] = [];
let body;
if (sources[0].includes("did")) {
body = {
id: chatID,
did: sources[0],
};
} else {
body = {
id: chatID,
indexIds: sources,
};
}
const {
messages,
append,
Expand All @@ -140,7 +101,10 @@ const ChatBody = () => {
api: apiUrl,
initialMessages,
id: chatID,
body,
body: {
id: chatID,
sources,
},
headers: {
"Content-Type": "application/json; charset=utf-8",
// Authorization: `Bearer ${session?.serialize()}`,
Expand All @@ -164,16 +128,6 @@ const ChatBody = () => {
scrollToBottom();
}, [messages, isLoading]);

// if (messages.length === 0) {
// return (
// <BodyPlaceholder
// tipBoxes={tipBoxes}
// darkMode={darkMode}
// sendMessage={setInput}
// />
// );
// }

return (
<>
<div
Expand Down Expand Up @@ -212,23 +166,6 @@ const ChatBody = () => {
<ChatScrollAnchor trackVisibility={isLoading} />
</div>
) : (
// <div
// style={{
// display: "flex",
// flexDirection: "column",
// height: "100%",
// justifyContent: "center",
// alignItems: "center",
// }}
// className="px-8"
// >
// <EmptyScreen
// contextMessage={getChatContextMessage()}
// setInput={setInput}
// indexIds={indexIds}
// defaultQuestions={defaultQuestions}
// />
// </div>
<BodyPlaceholder
tipBoxes={tipBoxes}
darkMode={darkMode}
Expand Down
4 changes: 2 additions & 2 deletions widget/src/components/ChatHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ const ChatHeader: React.FC = () => {
</Button>
)}
{session && <Avatar user={userProfile} size={28} />}
<button
{/* <button
onClick={onToggleDarkMode}
aria-label="toggle-dark-mode"
className="flex items-center rounded p-1"
>
{darkMode ? <Icons.Sun /> : <Icons.Moon />}
</button>
</button> */}
</div>
</header>
);
Expand Down
31 changes: 2 additions & 29 deletions widget/src/components/ai/chat-message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { CodeBlock } from "@/components/ai/ui/codeblock";
import { IconCheck, IconClose } from "@/components/ai/ui/icons";
import Avatar from "@/components/ui/Avatar";
import Button from "@/components/ui/Button";
import { appConfig } from "@/config";
import { useIndexChat } from "@/contexts/ChatContext";
import { Users } from "@/types/entity";
import { Message } from "ai";
Expand Down Expand Up @@ -60,24 +61,12 @@ export function ChatMessage({
/>
)
) : (
// <Avatar size={24} user={viewedProfile as Users} />
// <div
// style={{
// border: "1px solid #E2E8F0",
// borderRadius: "2px",
// padding: "1px 3px",
// }}
// >
// <div className={`flex items-start gap-3`}>
<img
src={viewedProfile?.avatar as any}
src={`${appConfig.ipfsGateway}/${viewedProfile?.avatar}`}
className="h-6 w-6 rounded-sm"
alt="Assistant Avatar"
/>
// </div>
// </div>
)}
{/* </div> */}
<div className="" style={{ overflow: "auto", width: "82%" }}>
<div style={{ overflowWrap: "break-word" }}>
{editingMessage?.id && index === editingIndex ? (
Expand All @@ -88,21 +77,6 @@ export function ChatMessage({
alignItems: "center",
}}
>
{/* <Input
autoFocus
style={{
border: "none",
outline: "none",
fontSize: "1.6rem",
marginBottom: "1rem",
marginRight: "1rem",
}}
ghost
value={editInput}
onChange={(e) => {
setEditInput(e.target.value);
}}
/> */}
<input
type="text"
className="bg-transparent text-sm focus:border-transparent focus:ring-0"
Expand All @@ -119,7 +93,6 @@ export function ChatMessage({
<p
style={{
marginTop: 0,
// fontSize: "1.4rem",
}}
className="w-full whitespace-break-spaces break-words pb-4 text-sm font-normal"
>
Expand Down
4 changes: 4 additions & 0 deletions widget/src/components/ai/ui/codeblock.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ h3 {
font-weight: 600;
padding-bottom: 1rem;
}

a {
text-decoration: underline;
}
3 changes: 2 additions & 1 deletion widget/src/components/ui/Avatar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { appConfig } from "@/config";
import { ShapeType } from "@/types";
import { Users } from "@/types/entity";
import { generateRandomColor, isSSR } from "@/utils/helper";
Expand Down Expand Up @@ -67,7 +68,7 @@ const Avatar = ({
{user ? (
user.avatar ? (
<img
src={`${user.avatar}`}
src={`${appConfig.ipfsGateway}/${user.avatar}`}
alt="profile_img"
className={rounded ? "rounded-full" : ""}
/>
Expand Down
Loading

0 comments on commit 0308637

Please sign in to comment.