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

Dev #2

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
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
66 changes: 43 additions & 23 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,47 @@ on:
- master

jobs:
docker:
runs-on: ubuntu-latest

push_to_registries:
name: Push Docker image to multiple registries
runs-on: self-hosted
permissions:
packages: write
contents: read
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GHCR_PAT }}

- name: Build and push
uses: docker/build-push-action@v2
with:
context: .
file: ./Eve/Dockerfile
push: true
tags: latest
- name: Check out the repo
uses: actions/checkout@v3

- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}

- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: |
webgrip/cogniswarm
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}

- name: Build and push Docker images
uses: docker/build-push-action@v4
with:
context: .
file: ./Eve/Dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
no-cache: true
21 changes: 16 additions & 5 deletions Eve/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,32 @@ RUN rm -rf /var/cache/apk/*
ENV VIRTUAL_ENV=/opt/venv
RUN python3 -m venv $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
WORKDIR /app

COPY Eve/requirements-compiled.txt .
RUN pip3 install --upgrade pip
RUN pip3 install --no-cache-dir -r requirements-compiled.txt

FROM builder AS prebuilt

COPY Eve/requirements-prebuilt.txt .
RUN pip3 install --upgrade pip
RUN pip3 install --no-cache-dir -r requirements-prebuilt.txt

COPY Eve/requirements.txt .
FROM prebuilt AS extra

COPY Eve/requirements-extra.txt .
RUN pip3 install --upgrade pip
RUN pip3 install --no-cache-dir -r requirements.txt
RUN pip3 install --no-cache-dir -r requirements-extra.txt

FROM builder AS final
FROM extra AS final

COPY --from=builder /opt/venv /opt/venv
COPY --from=extra /opt/venv /opt/venv
COPY --from=builder /usr/include/xlocale.h /usr/include/xlocale.h
ENV PATH=/opt/venv/bin:$PATH

WORKDIR /app

COPY ./Eve ./app

#CMD [ "/venv/bin/python", "main.py" ]
ENTRYPOINT ["tail", "-f", "/dev/null"]
130 changes: 30 additions & 100 deletions Eve/agents/AutonomousAgent.py
Original file line number Diff line number Diff line change
@@ -1,79 +1,32 @@
from functools import partial
from json import tool
import os
import math
from array import array
from langchain.llms.base import BaseLLM

from typing import Sequence

from .GenerativeAgent import GenerativeAgent

from langchain.prompts import load_prompt
from langchain.vectorstores import Weaviate
from langchain.retrievers import TimeWeightedVectorStoreRetriever
from langchain.embeddings import OpenAIEmbeddings
from langchain.schema import BaseRetriever
from langchain import PromptTemplate
from langchain.tools.base import BaseTool
from langchain.agents import ZeroShotAgent
from langchain.prompts import load_prompt


import os

import weaviate


WEAVIATE_HOST = os.getenv("WEAVIATE_HOST", "")
WEAVIATE_VECTORIZER = os.getenv("WEAVIATE_VECTORIZER", "")

def relevance_score_fn(score: float) -> float:
"""Return a similarity score on a scale [0, 1]."""
# This will differ depending on a few things:
# - the distance / similarity metric used by the VectorStore
# - the scale of your embeddings (OpenAI's are unit norm. Many others are not!)
# This function converts the euclidean norm of normalized embeddings
# (0 is most similar, sqrt(2) most dissimilar)
# to a similarity function (0 to 1)
return 1.0 - score / math.sqrt(2)
import weaviate
from .GenerativeAgent import GenerativeAgent

# Helper function to create a default memory retriever
def create_new_memory_retriever_default():
"""Create a new vector store retriever unique to the agent."""

client = weaviate.Client(
url=WEAVIATE_HOST,
additional_headers={"X-OpenAI-Api-Key": os.getenv("OPENAI_API_KEY")},
# auth_client_secret: Optional[AuthCredentials] = None,
# timeout_config: Union[Tuple[Real, Real], Real] = (10, 60),
# proxies: Union[dict, str, None] = None,
# trust_env: bool = False,
# additional_headers: Optional[dict] = None,
# startup_period: Optional[int] = 5,
# embedded_options=[],
)

embeddings_model = OpenAIEmbeddings(
#deployment="your-embeddings-deployment-name",
model="text-embedding-ada-002"
)

client = weaviate.Client(url=os.getenv("WEAVIATE_HOST"), additional_headers={"X-OpenAI-Api-Key": os.getenv("OPENAI_API_KEY")})
embeddings_model = OpenAIEmbeddings(model="text-embedding-ada-002")
vectorstore = Weaviate(client, "Paragraph", "content", embedding=embeddings_model, relevance_score_fn=relevance_score_fn)

return TimeWeightedVectorStoreRetriever(vectorstore=vectorstore, other_score_keys=["importance"], k=15)

class AutonomousAgent():
# Relevance score function
def relevance_score_fn(score: float) -> float:
return 1.0 - score / math.sqrt(2)

def make(
self,
name: str,
age: int,
traits: str,
status: str,
llm: BaseLLM,
daily_summaries: array,
reflection_threshold: int = 8,
memory_retriever: BaseRetriever = create_new_memory_retriever_default(),
verbose: bool = False
)->GenerativeAgent:
class AutonomousAgent:

return GenerativeAgent( # TODO current_plan
def make_agent(self, name: str, age: int, traits: str, status: str, llm: BaseLLM, daily_summaries: array, reflection_threshold: int = 8, memory_retriever: BaseRetriever = create_new_memory_retriever_default(), verbose: bool = False):
return GenerativeAgent(
name=name,
age=age,
traits=traits,
Expand All @@ -82,50 +35,27 @@ def make(
memory_retriever=memory_retriever,
llm=llm,
daily_summaries=daily_summaries,
verbose=verbose,
verbose=verbose
)

def getPrompt(generativeAgent: GenerativeAgent, objective, operating_system, tool_names, tools_summary)->PromptTemplate:
def get_prompt(self, generative_agent: GenerativeAgent, tools):

prompt = load_prompt("prompts/ryan.json")
prompt.partial(agent_summary=generativeAgent.get_summary(True))
prompt.format(
task = objective,
objective = objective,
agent_name = "Ryan",
operating_system = operating_system,
tool_names = tool_names,
tools_summary = tools_summary,
agent_summary = generativeAgent.get_summary(True)
)

return prompt

#return prompt.format(adjective="funny")


#if input_variables is None:
# input_variables = ["input", "agent_scratchpad"]
#return PromptTemplate(template=template, input_variables=input_variables)



#ZeroShotAgent.create_prompt(
# tools=tools,
# prefix=template,
# suffix="",
# input_variables=["objective", "task", "context", "agent_scratchpad"],
#)

#template="""You are {name}, an instance of an autonomous AGI agent, running on {operating_system}. This is a recent summary of you: {agent_summary}. You have been given a single task: {task}, based on the overarching objective: {objective}. The tools I can use are: {tools}. Think smart.\n{agent_scratchpad}""",
# input_variables=["operating_system", "tools", "objective", "task", "agent_scratchpad"],
# partial_variables={"agent_summary": generativeAgent.get_summary(), "agent_name": generativeAgent.name},
# tools=tools,
# # prefix="You are an AI who performs one task based on the following objective: {objective}. Take into account these previously completed tasks: {context}.",
# # suffix="Question: {task}",



return prompt


#prompt = load_prompt("prompts/ryan.json")
#prompt.partial()
return load_prompt("prompts/ryan.json")

#.format(
# task=objective,
# objective=objective,
# agent_name=generative_agent.name,
# operating_system=operating_system,
# tool_names=tool_names,
# tools_summary=tools_summary,
# agent_summary=generative_agent.get_summary(True)
# )
25 changes: 25 additions & 0 deletions Eve/helloworld.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
total 36
-rwxrwxrwx 1 root root 1462 Apr 27 05:30 Dockerfile
-rwxrwxrwx 1 root root 8032 Apr 20 17:25 Eve.pyproj
-rwxrwxrwx 1 root root 227 Apr 15 16:07 Eve.pyproj.user
drwxr-xr-x 1 root root 4096 Apr 27 00:11 __pycache__
drwxrwxrwx 1 root root 4096 Apr 28 01:27 agents
drwxrwxrwx 1 root root 4096 Apr 28 01:27 chains
drwxrwxrwx 1 root root 4096 Apr 28 01:27 characters
drwxrwxrwx 1 root root 4096 Apr 28 01:27 data
drwxrwxrwx 1 root root 4096 Apr 26 06:40 env
drwxrwxrwx 1 root root 4096 Apr 28 01:26 experiments
-rw-r--r-- 1 root root 0 Apr 28 20:04 helloworld.md
-rwxrwxrwx 1 root root 9830 Apr 28 20:01 main.py
drwxrwxrwx 1 root root 4096 Apr 28 01:26 old
drwxrwxrwx 1 root root 4096 Apr 28 19:08 output_parsers
drwxrwxrwx 1 root root 4096 Apr 28 01:58 prompts
drwxrwxrwx 1 root root 4096 Apr 28 01:26 protos
-rwxrwxrwx 1 root root 142 Apr 27 00:53 requirements-compiled.txt
-rwxrwxrwx 1 root root 36 Apr 27 12:54 requirements-extra.txt
-rwxrwxrwx 1 root root 99 Apr 26 23:51 requirements-prebuilt.txt
drwxrwxrwx 1 root root 4096 Apr 17 06:45 retrievers
drwxrwxrwx 1 root root 4096 Apr 28 01:26 toddleragi
-rwxrwxrwx 1 root root 4131 Apr 25 16:03 tools.py
drwxrwxrwx 1 root root 4096 Apr 28 01:26 vectorstores
-rwxrwxrwx 1 root root 1180 Apr 17 07:18 weaviate_schema.py
Loading