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

Updated Chat Assistant and Social Post Generator tutorials #629

Merged
merged 6 commits into from
Dec 3, 2024

Conversation

AccordionGuy
Copy link
Contributor

I’ve updated the Chat Assistant and Social Post Generator tutorials based on @ajot’s and @samjulien’s revisions, as requested in this Jira ticket.

Copy link
Contributor

@samjulien samjulien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are great and like 85% of the way there. I stepped through the chat one and left notes, and then read through the social post one and left more notes.

I've run out of time to go through the social one one step by step. You can apply basically all of the suggestions for the chat assistant one to this one (e.g. linking to guides, etc) and then tag @ajot to step through the social post one.

- **A Writer account:** Create a free account at [writer.com](https://writer.com).
- **Python 3.7+**: Use the installer from [python.org](https://www.python.org/downloads/).
- **pip:** This command-line application comes with Python and is used for installing Python packages, including those from Writer.
- **Your favorite code editor:** You'll need one — such as Visual Studio Code, Notepad++, Vim, Emacs, or any text editor made for programming — to write the back-end code behind the user interface.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's note that the code editor is optional since you can use the in-browser one

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.


Before starting, ensure you have:

- **A Writer account:** Create a free account at [writer.com](https://writer.com).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a link to the Writer AI Studio signup: https://app.writer.com/aistudio/signup.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

```bash Standard port
writer edit chat-assistant
```
<Step title="Create a .env file">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a note that if they are using the in-browser code editor, they can instead export the key in their terminal session.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated. I decided to keep the tutorial simple by skipping the .env file entirely and simply exporting the key to their terminal session.


Before starting, ensure you have:

- **A Writer account:** Create a free account at [writer.com](https://writer.com).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto on Writer AI Studio signup/text https://app.writer.com/aistudio/signup

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

- **A Writer account:** Create a free account at [writer.com](https://writer.com).
- **Python 3.7+**: Use the installer from [python.org](https://www.python.org/downloads/).
- **pip:** This command-line application comes with Python and is used for installing Python packages, including those from Writer.
- **Your favorite code editor:** You'll need one — such as Visual Studio Code, Notepad++, Vim, Emacs, or any text editor made for programming — to write the back-end code behind the user interface.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto on this being optional and point out the in-browser editor as an option

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

This code uses the streaming function of the `Conversation` method, which is a wrapper for the `chat` API endpoint. Each chunk returned from the stream is added to the `conversation` variable in the application state.
The `generate_completion()` function will be called when the user enters a prompt, which is contained in the `payload` object. The `payload` object is added to the `conversation` object contained in the application's `state`, which adds the user's prompt to the record of the conversation between the user and the LLM.

After adding the user's prompt to the conversational record, `generate_completion()` calls the `conversation` object's `stream_complete()` method, which generates an LLM completion based on the conversation so far. As its name implies, `stream_complete()` returns the completion as a stream of text chunks, which are captured and added to the `conversation` object.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's link to the AI module guide at the end of this if people want to learn more, for example if they want to learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

```python
# Initialize the state
wf.init_state({
"conversation": writer.ai.Conversation(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be worth calling out here that you can pass configuration into this such as what model you want to use and then link to the AI module guide.


![Finished chat assistant project](/framework/images/tutorial/chat/chat_assistant_6.png)
The application is ready to run locally!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make sure that it's clear somewhere in this tutorial and at this part that you can always see the running application using the "Preview" button at the top. As a reader I'd be wondering:

  • Why do I have to quit and re-run it in order to see my changes?
  • What's the difference between writer edit Preview and writer run

Let's answer those questions here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.


```python
def generate_completion(state, payload):
print(f"Here's what the user entered: {payload['content']}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love all of the print statements here for debugging, but you can just call it out in the para below? Something about how there are some optional print statements in there to help with debugging, feel free to remove them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

@@ -2,218 +2,410 @@
title: "Social post generator"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've run out of time to go through this one step by step, but you could apply basically all of the suggestions for the chat assistant one to this one (e.g. linking to guides, etc) and then tag @ajot to step through the social post one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Contributor

@samjulien samjulien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few image issues but everything else is looking good!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AccordionGuy can you retake this so you don't see the cursor in the corner?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AccordionGuy can you retake this so you don't see the cursor in the corner?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AccordionGuy can you retake this so you don't see the cursor in the corner?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AccordionGuy can you retake this so you don't see the cursor in the corner?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AccordionGuy can you retake this so you don't see the cursor in the corner?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!


![The working social post generator, with the project editor in "Preview" mode and the log pane displayed](/framework/images/tutorial/chat/chat_assistant_2g.png)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AccordionGuy this image isn't displaying for me, may need to double-check it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

@AccordionGuy
Copy link
Contributor Author

@ramedina86 I’ve updated the Chat assistant and Social post generator tutorials as requested by @samjulien. I’ve made the final changes and they’re ready to be published.


There are two ways to edit `main.py`:

1. **In your browser.** Click on the **Code** button near the top right corner of the project editor page. A pane with the name **Code** will appear at the bottom half of the screen, displaying and allowing you to edit the contents of `main.py`.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

near the top right corner

When updating screenshots, please make sure that these references are also updated.


Before starting, ensure you have:

- **A Writer account:** You'll need an account to use Writer Framework, and [you can sign up for a free one](https://app.writer.com/aistudio/signup).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll need an account to use Writer Framework

Can we change this? In fact, we should start emphasizing everywhere that you don't need a Writer account to use Writer Framework, only to use Writer's AI features which are accessible via the Framework.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah good catch @ramedina86 -- yes @AccordionGuy let's say something like "You'll need an account to use the AI module in Writer Framework"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, be sure to do it in both tutorials too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated!

@AccordionGuy
Copy link
Contributor Author

@samjulien @ramedina86 I’ve made the updates — new screenshots and confirmed that the text matches the updated UI.

@ramedina86 ramedina86 merged commit a041f1a into writer:dev Dec 3, 2024
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants