Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add trunk & fmt #17

Merged
merged 2 commits into from
Feb 15, 2025
Merged
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
Binary file modified .assets/perplexica-screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions .github/workflows/trunk-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Pull Request
on: [pull_request]
concurrency:
group: ${{ github.head_ref || github.run_id }}
cancel-in-progress: true

permissions: read-all

jobs:
trunk_check:
name: Trunk Code Quality Runner
runs-on: ubuntu-latest
permissions:
checks: write # For trunk to post annotations
contents: read # For repo checkout

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Trunk Code Quality
uses: trunk-io/trunk-action@v1
9 changes: 9 additions & 0 deletions .trunk/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*out
*logs
*actions
*notifications
*tools
plugins
user_trunk.yaml
user.yaml
tmp
4 changes: 4 additions & 0 deletions .trunk/configs/.hadolint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Following source doesn't work in most setups
ignored:
- SC1090
- SC1091
2 changes: 2 additions & 0 deletions .trunk/configs/.markdownlint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Prettier friendly markdownlint config (all formatting rules disabled)
extends: markdownlint/style/prettier
7 changes: 7 additions & 0 deletions .trunk/configs/.yamllint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
rules:
quoted-strings:
required: only-when-needed
extra-allowed: ['{|}']
key-duplicates: {}
octal-values:
forbid-implicit-octal: true
14 changes: 14 additions & 0 deletions .trunk/configs/svgo.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export default {
plugins: [
{
name: 'preset-default',
params: {
overrides: {
removeViewBox: false, // https://github.com/svg/svgo/issues/1128
sortAttrs: true,
removeOffCanvasPaths: true,
},
},
},
],
};
40 changes: 40 additions & 0 deletions .trunk/trunk.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# This file controls the behavior of Trunk: https://docs.trunk.io/cli
# To learn more about the format of this file, see https://docs.trunk.io/reference/trunk-yaml
version: 0.1
cli:
version: 1.22.10
# Trunk provides extensibility via plugins. (https://docs.trunk.io/plugins)
plugins:
sources:
- id: trunk
ref: v1.6.7
uri: https://github.com/trunk-io/plugins
# Many linters and tools depend on runtimes - configure them here. (https://docs.trunk.io/runtimes)
runtimes:
enabled:
- node@18.20.5
- python@3.10.8
# This is the section where you manage your linters. (https://docs.trunk.io/check/configuration)
lint:
ignore:
- linters: [ALL]
paths:
- "*.dockerfile"
enabled:
- checkov@3.2.370
- git-diff-check
- hadolint@2.12.1-beta
- markdownlint@0.44.0
- osv-scanner@1.9.2
- oxipng@9.1.3
- prettier@3.5.1
- svgo@3.3.2
- taplo@0.9.3
- trufflehog@3.88.8
- yamllint@1.35.1
actions:
enabled:
- trunk-announce
- trunk-check-pre-push
- trunk-fmt-pre-commit
- trunk-upgrade-available
11 changes: 8 additions & 3 deletions API_INTEGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ Currently, the API does not require authentication. However, this may change in
"gpt-3.5-turbo": {}
},
"anthropic": {
"Claude 3.5 Sonnet": {},
"Claude 3.5 Sonnet": {}
}
},
"embeddingModelProviders": {
"openai": {
"text-embedding-ada-002": {}
},
}
}
}
```
Expand Down Expand Up @@ -150,7 +150,10 @@ Messages sent to the WebSocket should be JSON strings with the following structu
"focusMode": "cairoBookSearch",
"history": [
["human", "Hello! I'm interested in learning about Cairo."],
["ai", "Hello! I'd be happy to help you learn about Cairo. Cairo is a programming language designed for writing provable programs, particularly smart contracts for the StarkNet platform. What specific aspect of Cairo would you like to know more about?"],
[
"ai",
"Hello! I'd be happy to help you learn about Cairo. Cairo is a programming language designed for writing provable programs, particularly smart contracts for the StarkNet platform. What specific aspect of Cairo would you like to know more about?"
],
["human", "Can you help me understand how Cairo smart contracts work?"]
]
}
Expand Down Expand Up @@ -207,6 +210,8 @@ Error messages will be sent as JSON with the following structure:
- The system uses a focus mode to determine the context of the conversation. Ensure the correct focus mode is specified in each message.
- The chat history should be maintained on the client-side and sent with each message for context.
- Handle WebSocket disconnections gracefully and implement reconnection logic if necessary.

```

This formatted version of the document includes improved examples for each section, making it easier for external teams to understand and integrate with the AI chat system.
```
55 changes: 16 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
- [Features](#features)
- [Installation](#installation)
- [Getting Started with Docker (Recommended)](#getting-started-with-docker-recommended)
- [Non-Docker Installation](#non-docker-installation)
- [Ollama Connection Errors](#ollama-connection-errors)
- [Using as a Search Engine](#using-as-a-search-engine)
- [One-Click Deployment](#one-click-deployment)
- [Upcoming Features](#upcoming-features)
- [Support Us](#support-us)
- [Donations](#donations)
Expand Down Expand Up @@ -56,21 +53,22 @@ There are mainly 2 ways of installing Starknet Agent - With Docker, Without Dock
3. After cloning, navigate to the directory containing the project files.

4. Setup your databases on [MongoDB Atlas](https://www.mongodb.com/products/platform/atlas-vector-search).

- Create a new cluster.
- Create a new database for each of the focus modes you intend to use. A single database for the ecosystem-wide mode is enough, e.g.: `starknet-ecosystem`.
- Create a new collection inside each database that will store the embeddings. e.g. `all-chunks` for the `starknet-ecosystem` database.
- Create a vectorSearch index named **default** on the collection (tab `Atlas Search`). Example index configuration:
```json
{
"fields": [
{
"fields": [
{
"numDimensions": 2048,
"path": "embedding",
"similarity": "cosine",
"type": "vector"
}
]
"numDimensions": 2048,
"path": "embedding",
"similarity": "cosine",
"type": "vector"
}
]
}
```

5. Copy the `sample.config.toml` file to a `config.toml`. For Docker setups, you need only fill in the following fields:
Expand All @@ -88,57 +86,36 @@ There are mainly 2 ways of installing Starknet Agent - With Docker, Without Dock
MONGODB_URI = "mongodb+srv://mongo:..."
DB_NAME = "starknet-ecosystem"
COLLECTION_NAME = "all-chunks"
```
```
- Other databases are for focused modes (in a single resource). You only need to fill these ones if you want to use the associated focused mode. You will need to create databases for each of the focused modes.
- Models: The `[HOSTED_MODE] table defines the underlying LLM model used. We recommend using:
```

```toml
[HOSTED_MODE]
DEFAULT_CHAT_PROVIDER = "anthropic"
DEFAULT_CHAT_MODEL = "Claude 3.5 Sonnet"
DEFAULT_EMBEDDING_PROVIDER = "openai"
DEFAULT_EMBEDDING_MODEL = "Text embedding 3 large"
```

5. Generate the embeddings for the databases. You can do this by running the `generateEmbeddings.ts` script with bun. If you followed the example above, you will need to run the script with option `4 (Everything)` for the `starknet-ecosystem` database.
6. Generate the embeddings for the databases. You can do this by running the `generateEmbeddings.ts` script with bun. If you followed the example above, you will need to run the script with option `4 (Everything)` for the `starknet-ecosystem` database.

```bash
bun run src/scripts/generateEmbeddings.ts
```

5. Ensure you are in the directory containing the `docker-compose.yaml` file and execute:
7. Ensure you are in the directory containing the `docker-compose.yaml` file and execute:

```bash
docker-compose -f docker-compose.dev-hosted.yml up
```

6. Wait a few minutes for the setup to complete. You can access Starknet Agent at http://localhost:3000 in your web browser.
8. Wait a few minutes for the setup to complete. You can access Starknet Agent at http://localhost:3000 in your web browser.

**Note**: After the containers are built, you can start Starknet Agent directly from Docker without having to open a terminal.


### Ollama Connection Errors

If you're encountering an Ollama connection error, it is likely due to the backend being unable to connect to Ollama's API. To fix this issue you can:

1. **Check your Ollama API URL:** Ensure that the API URL is correctly set in the settings menu.
2. **Update API URL Based on OS:**

- **Windows:** Use `http://host.docker.internal:11434`
- **Mac:** Use `http://host.docker.internal:11434`
- **Linux:** Use `http://<private_ip_of_host>:11434`

Adjust the port number if you're using a different one.

3. **Linux Users - Expose Ollama to Network:**

- Inside `/etc/systemd/system/ollama.service`, you need to add `Environment="OLLAMA_HOST=0.0.0.0"`. Then restart Ollama by `systemctl restart ollama`. For more information see [Ollama docs](https://github.com/ollama/ollama/blob/main/docs/faq.md#setting-environment-variables-on-linux)

- Ensure that the port (default is 11434) is not blocked by your firewall.

## Upcoming Features

- [x] Add settings page
- [x] Adding support for local LLMs
- [x] History Saving features
- [ ] Expanding coverage of Starknet-related resources
- [ ] Adding an Autonomous Agent Mode for more precise answers

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.dev-hosted.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ services:
ports:
- 3001:3001
extra_hosts:
- 'host.docker.internal:host-gateway'
- host.docker.internal:host-gateway
networks:
- starknet-agent-network
environment:
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ services:
- searxng
# - cairobook-ingest
extra_hosts:
- 'host.docker.internal:host-gateway'
- host.docker.internal:host-gateway
networks:
- starknet-agent-network
environment:
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.prod-hosted.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ services:
depends_on:
- searxng
extra_hosts:
- 'host.docker.internal:host-gateway'
- host.docker.internal:host-gateway
networks:
- starknet-agent-network
restart: unless-stopped
Expand Down
6 changes: 3 additions & 3 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ services:
volumes:
- backend-dbstore:/home/starknet-agent/data
extra_hosts:
- 'host.docker.internal:host-gateway'
- host.docker.internal:host-gateway
networks:
- starknet-agent-network
environment:
Expand Down Expand Up @@ -63,8 +63,8 @@ services:
volumes:
- ssl_data:/etc/resty-auto-ssl
environment:
ALLOWED_DOMAINS: '(backend.)?agent.starknet.id'
SITES: 'backend.agent.starknet.id=starknet-agent-backend:3001;agent.starknet.id=starknet-agent-frontend:3000'
ALLOWED_DOMAINS: (backend.)?agent.starknet.id
SITES: backend.agent.starknet.id=starknet-agent-backend:3001;agent.starknet.id=starknet-agent-frontend:3000
networks:
- starknet-agent-network
depends_on:
Expand Down
2 changes: 1 addition & 1 deletion docs/architecture/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Starknet Agent's Architecture
# Starknet Agent's Architecture

Starknet Agent's architecture consists of the following key components:

Expand Down
6 changes: 3 additions & 3 deletions docs/architecture/WORKING.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## How does Starknet Agent work?
# How does Starknet Agent work?

Curious about how Starknet Agent works? Don't worry, we'll cover it here. Before we begin, make sure you've read about the architecture of Starknet Agent to ensure you understand what it's made up of. Haven't read it? You can read it [here](https://github.com/cairo-book/starknet-agent/tree/master/docs/architecture/README.md).

Expand All @@ -7,8 +7,8 @@
1. The message is sent via WS to the backend server where it invokes the chain. The chain will depend on your focus mode. For this example, let's assume we use the "starknetDocs" focus mode.
2. The chain is now invoked; first, the message is passed to another chain where it first predicts (using the chat history and the question) where it is reformulated for a more precise input.
3. The reformulated query returned by the first chain is converted into an embedding. We perform a similarity search to find the most relevant sources to answer the query in the appropriate vector store.
5. After all this is done, the sources are passed to the response generator. This chain takes all the chat history, the query, and the sources. It generates a response that is streamed to the UI.
4. After all this is done, the sources are passed to the response generator. This chain takes all the chat history, the query, and the sources. It generates a response that is streamed to the UI.

### How are the answers cited?
# How are the answers cited?

Check notice on line 12 in docs/architecture/WORKING.md

View workflow job for this annotation

GitHub Actions / Trunk Check

markdownlint(MD025)

[new] Multiple top-level headings in the same document

The LLMs are prompted to do so. We've prompted them so well that they cite the answers themselves, and using some UI magic, we display it to the user.
2 changes: 1 addition & 1 deletion searxng/limiter.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[botdetection.ip_limit]
# activate link_token method in the ip_limit method
link_token = true
link_token = true
7 changes: 4 additions & 3 deletions searxng/settings.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
use_default_settings: true

general:
instance_name: 'searxng'
instance_name: searxng

search:
autocomplete: 'google'
autocomplete: google
formats:
- html
- json

server:
secret_key: 'a2fb23f1b02e6ee83875b09826990de0f6bd908b6638e8c10277d415f6ab852b' # Is overwritten by ${SEARXNG_SECRET}
# checkov: S105
secret_key: a2fb23f1b02e6ee83875b09826990de0f6bd908b6638e8c10277d415f6ab852b # Is overwritten by ${SEARXNG_SECRET}

engines:
- name: wolframalpha
Expand Down
Loading
Loading