ProductPromotion
Logo

Angular.JS

made by https://0x3d.site

GitHub - c-o-l-i-n/ng-generative-ai-demo: 🤖 Stream realtime generative AI to your Angular app using Google Gemini, HttpClient, RxJS, and Signals
🤖 Stream realtime generative AI to your Angular app using Google Gemini, HttpClient, RxJS, and Signals - c-o-l-i-n/ng-generative-ai-demo
Visit Site

GitHub - c-o-l-i-n/ng-generative-ai-demo: 🤖 Stream realtime generative AI to your Angular app using Google Gemini, HttpClient, RxJS, and Signals

GitHub - c-o-l-i-n/ng-generative-ai-demo: 🤖 Stream realtime generative AI to your Angular app using Google Gemini, HttpClient, RxJS, and Signals

🤖 Angular Generative AI Demo

Demo

🤔 Why does this matter?

Generative AI is changing the way we interact with technology. As AI chatbots become more commonplace, users expect certain behaviors from our apps, such as realtime text updates. Using LLM APIs, Signals, and some RxJS magic, we can create modern AI-driven user experiences.

🏃 Getting started

[!NOTE]
The Gemini API is free, so long as you're willing to share all of your usage data with Google.

  1. Run git clone https://github.com/c-o-l-i-n/ng-generative-ai-demo.git to clone this repo.

  2. Visit the Google AI Studio to generate an API key.

  3. Create a .env file in the project root with your API key:

    GOOGLE_AI_STUDIO_API_KEY=paste-api-key-here
    
  4. Run npm install to install dependencies.

  5. Run npm run server to start the backend server (server.ts) on port 3000.

  6. In another terminal, run npm start to start the Angular dev server on port 4200.

  7. Navigate to http://localhost:4200/

🔑 Key takeaways

  • Manage State with Signals: Keep track of the chat state (list of messages and whether the LLM is generating a new message) with Angular Signals.

  • Realtime Text Streaming with RxJS Observables: Utilize RxJS to react to realtime updates from the LLM API.

  • HTTP Client Configuration: Configure the Angular HTTP client to handle realtime text streams:

    1. Provide the HTTP client "with fetch" in app.config.ts:
    provideHttpClient(withFetch());
    
    1. Tell the HTTP client to observe text events and report progress:
    this.http.post('http://localhost:3000/message', prompt, {
      responseType: 'text',
      observe: 'events',
      reportProgress: true,
    });
    
  • Blinking Cursor: Create a blinking cursor effect using the CSS ::after pseudo-element and CSS @keyframes:

    .message {
      &.generating {
        &::after {
          content: '▋';
          animation: fade-cursor ease-in-out 500ms infinite alternate;
        }
      }
    }
    
    @keyframes fade-cursor {
      from {
        opacity: 25%;
      }
      to {
        opacity: 100%;
      }
    }
    

🔭 Files to explore

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory