Skip to content

Commit

Permalink
Merge pull request #15 from luckysanpedro/codebase-restructure
Browse files Browse the repository at this point in the history
adding docs
  • Loading branch information
shroominic authored Jan 28, 2024
2 parents 070f0af + 1fbbb49 commit fe29b54
Show file tree
Hide file tree
Showing 17 changed files with 1,856 additions and 25 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
[![Pydantic v2](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/pydantic/pydantic/main/docs/badge/v2.json)](https://docs.pydantic.dev/latest/contributing/#badges)
[![Twitter Follow](https://img.shields.io/twitter/follow/shroominic?style=social)](https://x.com/shroominic)

```bash
> pip install funcchain
```

<div class="termy">
```bash
$ > pip install funcchain
```
</div>
## Introduction

`funcchain` is the *most pythonic* way of writing cognitive systems. Leveraging pydantic models as output schemas combined with langchain in the backend allows for a seamless integration of llms into your apps.
Expand Down
27 changes: 27 additions & 0 deletions docs/css/custom.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
.termynal-comment {
color: #4a968f;
font-style: italic;
display: block;
}

.termy [data-termynal] {
white-space: pre-wrap;
}

a.external-link::after {
/* \00A0 is a non-breaking space
to make the mark be on the same line as the link
*/
content: "\00A0[↪]";
}

a.internal-link::after {
/* \00A0 is a non-breaking space
to make the mark be on the same line as the link
*/
content: "\00A0↪";
}

.shadow {
box-shadow: 5px 5px 10px #999;
}
109 changes: 109 additions & 0 deletions docs/css/termynal.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/**
* termynal.js
*
* @author Ines Montani <[email protected]>
* @version 0.0.1
* @license MIT
*/

:root {
--color-bg: #252a33;
--color-text: #eee;
--color-text-subtle: #a2a2a2;
}

[data-termynal] {
width: 750px;
max-width: 100%;
background: var(--color-bg);
color: var(--color-text);
/* font-size: 18px; */
font-size: 15px;
/* font-family: 'Fira Mono', Consolas, Menlo, Monaco, 'Courier New', Courier, monospace; */
font-family: 'Roboto Mono', 'Fira Mono', Consolas, Menlo, Monaco, 'Courier New', Courier, monospace;
border-radius: 4px;
padding: 75px 45px 35px;
position: relative;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}

[data-termynal]:before {
content: '';
position: absolute;
top: 15px;
left: 15px;
display: inline-block;
width: 15px;
height: 15px;
border-radius: 50%;
/* A little hack to display the window buttons in one pseudo element. */
background: #d9515d;
-webkit-box-shadow: 25px 0 0 #f4c025, 50px 0 0 #3ec930;
box-shadow: 25px 0 0 #f4c025, 50px 0 0 #3ec930;
}

[data-termynal]:after {
content: 'bash';
position: absolute;
color: var(--color-text-subtle);
top: 5px;
left: 0;
width: 100%;
text-align: center;
}

a[data-terminal-control] {
text-align: right;
display: block;
color: #aebbff;
}

[data-ty] {
display: block;
line-height: 2;
}

[data-ty]:before {
/* Set up defaults and ensure empty lines are displayed. */
content: '';
display: inline-block;
vertical-align: middle;
}

[data-ty="input"]:before,
[data-ty-prompt]:before {
margin-right: 0.75em;
color: var(--color-text-subtle);
}

[data-ty="input"]:before {
content: '$';
}

[data-ty][data-ty-prompt]:before {
content: attr(data-ty-prompt);
}

[data-ty-cursor]:after {
content: attr(data-ty-cursor);
font-family: monospace;
margin-left: 0.5em;
-webkit-animation: blink 1s infinite;
animation: blink 1s infinite;
}


/* Cursor animation */

@-webkit-keyframes blink {
50% {
opacity: 0;
}
}

@keyframes blink {
50% {
opacity: 0;
}
}
115 changes: 115 additions & 0 deletions docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,118 @@ The funcchain project makes it really simple to leverage large language models i
## Advanced Examples

For advanced examples, checkout the examples directory [here](https://github.com/shroominic/funcchain/tree/main/examples)

## Simple chatgpt rebuild with memory/history.
!!! Example
chatgpt.py [Example](https://github.com/shroominic/funcchain/blob/main/examples/chatgpt.py)



```python
from funcchain import chain, settings
from funcchain.utils.memory import ChatMessageHistory

settings.llm = "openai/gpt-4"
settings.console_stream = True

history = ChatMessageHistory()


def ask(question: str) -> str:
return chain(
system="You are an advanced AI Assistant.",
instruction=question,
memory=history,
)


def chat_loop() -> None:
while True:
query = input("> ")

if query == "exit":
break

if query == "clear":
global history
history.clear()
print("\033c")
continue

ask(query)


if __name__ == "__main__":
print("Hey! How can I help you?\n")
chat_loop()
```



<div class="termy">
```terminal
initial print function:
$ Hey! How can I help you?
$ >

userprompt:
$ > Say that Funcchain is cool

assistant terminal asnwer:
$ Funcchain is cool.
```
</div>

## Instructions

Import nececary funcchain components

```python
from funcchain import chain, settings
from funcchain.utils.memory import ChatMessageHistory
```
#
Settings
```python
settings.llm = "openai/gpt-4"
settings.console_stream = True
```
!!! Options
Funcchain supports multiple LLMs and has the ability to stream received LLM text instead of waiting for the complete answer. For configuration options, see below:

```markdown
- `settings.llm`: Specify the language model to use. See MODELS.md for available options.
- Streaming: Set `settings.console_stream` to `True` to enable streaming,
or `False` to disable it.
```

[MODELS.md]([MODELS.md](https://github.com/shroominic/funcchain/blob/main/MODELS.md))

#
Establish a chat history

```python
history = ChatMessageHistory()
```
Stores messages in an in memory list. This will crate a thread of messages.

See [memory.py] //Todo: Insert Link

#
Ask function explained
```python
def ask(question: str) -> str:
return chain(
system="You are an advanced AI Assistant.",
instruction=question,
memory=history,
)
```

This function sends a question to the Funcchain chain function.

It sets the system context as an advanced AI Assistant and passes the question as an instruction.

The history object is used to maintain a thread of messages for context.

The function returns the response from the chain function.
Loading

0 comments on commit fe29b54

Please sign in to comment.